Originally posted by Peter den Haan:
Without a stack trace and perhaps a snippet of relevant code we can't even start to help you. But on the topic of threads, beware that most Swing methods are not threadsafe.
- Peter
Okay heres a sample of my code:
The panel to draw on is passed from another method
class ButtonPanel extends JPanel
{
ScreenUpdate su = new ScreenUpdate(this);
public ButtonPanel ()
{
}
su.start();
}
public void DefineButton(
String name, final int lightid,final int lightxa, final int lightya,final int lightxb, final int lightyb)
{
try
{
su.draw(lightid,0,0,0,0);
} ^^^^^^^^^----This throws an exception
}
}
class ScreenUpdate extends Thread
{
private JPanel box;
public ScreenUpdate(JPanel c)
{
box = c;
}
public boolean draw(int lightid,int lightxa,int lightya, int lightxb, int lightyb)
{
Graphics g = box.getGraphics();
g.fillOval(btnx,btny,15,15);
g.setColor(Color.black);
g.drawOval(btnx,btny,15,15);
return lightstate[lightid];
}
public void run(){
while(true){
try
{
draw(SPlight,0,0,0,0);
^^^^^^^^^----This throws an exception everytime its called
querysp();
}
catch (Exception e){}
try
{
Thread.sleep(1000);}
catch( InterruptedException e) {
System.err.println("Caught exception at Run" + e.toString());
}
}
}