while running multiple thread repaint isnt being called....
Code:
import java.applet.*;
import java.awt.*;
public class TrafficControl extends Applet implements Runnable{
Thread t;
Color c1,c2,c3;
public void init()
{
for(int a=1;;a++)
{
if(a%3==1)starter("RED");
else if(a%3==2)starter("YELLOW");
else starter("GREEN");
try{
t.join();
Thread.sleep(1000);
} catch(Exception e){System.out.println(e);}
}
}
public void starter(String s)
{
t=new Thread(this,s);
t.start();
}
public void run()
{
System.out.println(t);
String pro=t.getName();
c1=c2=c3=Color.WHITE;
if(pro.equals("RED"))
c1=Color.RED;
else if(pro.equals("YELLOW"))
c2=Color.YELLOW;
else
c3=Color.GREEN;
repaint(); //this repaint is nvr called
}
public void paint(Graphics g)
{
System.out.println("In paint"); //thread nvr enters paint???? y ??
//it'll only enter ven infinite loop will finish
g.drawRect(0, 0, 30, 80);
g.setColor(c1);
g.fillOval(5, 5, 20, 20);
g.setColor(c2);
g.fillOval(5, 30, 20, 20);
g.setColor(c3);
g.fillOval(5, 55, 20, 20);
}
}