import java.awt.*; import java.util.*; public class TimerThread extends Canvas implements Runnable { static final int GAME_TIME = 1; // minutes before turn has passed static final int WIDTH = 100; static final int HEIGHT = 100; Image buffer; Graphics bg; Thread runner = null; int timeLeft = 0; ClientThread ct; /** * Call this ONLY once! */ public TimerThread(ClientThread c) { ct = c; resize(WIDTH,HEIGHT); runner = new Thread(this); runner.setPriority(Thread.MAX_PRIORITY-1); //want this updated as often as possible } public void kickStart() { runner.start(); } public void run() { buffer = createImage(WIDTH,HEIGHT); bg = buffer.getGraphics(); while(true) { for(int i=60;i>0;i--) { timeLeft = i; paint(this.getGraphics()); // UGLY !!! (but necessary...) // System.out.println("Tick..."+i); try{ Thread.sleep(GAME_TIME*1000); } catch(InterruptedException e){} } System.out.println("nu skickar vi info till fod:en... "); ct.endOfTurn(); } } public void update(Graphics g) { //override paint(g); } public void paint(Graphics g) { // System.out.println("bg:"+bg); bg.clearRect(0,0,WIDTH,HEIGHT); bg.setColor(Color.red); bg.fillArc(0,0,WIDTH,HEIGHT, 90, timeLeft*6); g.drawImage(buffer,0,0,this); // System.out.println("arc:" + timeLeft*6); } /* public static void main(String[] a) { new TimerThread(); } */ }