Hi could anyone help me tell what is wrong with this code which produce error illegal start sxpression, I know that missing bracket before the the second sychnorized method but if add a bracket,it produce alot of error which is not actual error. Thanks alot
Code:import java.awt.*; public class AppletTest extends java.applet.Applet { private Hare hare; private Tortoise torties; private Image harePic, tortoisePic; private final int HARE_TURN = 0; private final int TORT_TURN = 0; private int turn = 0; private int sleepTime = 200; public void init() { hare = new Hare(); torties = new Tortoise(); harePic = new Image(""); tortoisePic = new Image(""); } public void paint(Graphics g) { g.drawImage(harePic,hare.getPosition(),40,this); g.drawImage(tortoisePic,tortoise.getPosition(),100,this); } public synchronized void HareAdvance() { while(turn == HARE_TURN) { try{ wait(); }catch(InterruptedException e ) {} repaint(); try { Thread.sleep(sleepTime); }catch(InterruptedException e ) {} turn = TORT_TURN - turn; } public synchronized void TortoiseAdvance() { while(turn != HARE_TURN ) { try{ wait(); }catch(InterruptedException e ) {} } repaint(); try { Thread.sleep(sleepTime); }catch(InterruptedException e ) {} turn = TORT_TURN - turn; } }




Reply With Quote