Maybe posts like this have been posted before but am really stuck with this..so i need help please...
I have a simple applet code..it marquees a line...i want to make it stop at a particular interval and make it continue on mouse clicking...so I use wait()..but on using notify() nothing happens...can anyone plz help...and forgive me if there is any stupid errors in the code...
Thanks in advance...
I have a simple applet code..it marquees a line...i want to make it stop at a particular interval and make it continue on mouse clicking...so I use wait()..but on using notify() nothing happens...can anyone plz help...and forgive me if there is any stupid errors in the code...
Code:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Applet4S extends Applet implements MouseListener{
String msg;
int x=20,y=30,i;
public void init()
{
setForeground(Color.blue);
addMouseListener(this);
}
public void paint(Graphics g)
{
g.drawString(msg, x, y);
}
public void mouseExited(MouseEvent me){}
public void mouseEntered(MouseEvent me){}
public void mousePressed(MouseEvent me){}
public void mouseReleased(MouseEvent me){}
public void mouseClicked(MouseEvent me)
{
showStatus("Mouse is clicked");
resumenow();
}
synchronized void resumenow()
{
notify();
}
synchronized void suspendnow()
{
try
{
showStatus("Thread is in suspendnow()");
wait();
}
catch (InterruptedException ex) {}
}
public void start()
{
msg = "Started";
for(i=0;;i++)
{
if(x>200)
{
x=20;
}
x=x+1;
repaint();
if(i%5==0)
{
showStatus("This thread is gonna wait");
suspendnow();
}
}
}
}
Thanks in advance...