adding components to a JApplet using threads
I'm in the process of converting a game to run in a JApplet. The problem i'm running into at the moment is that when the game starts I spawn a thread to do all my processing in and want to change the currently displayed JPanel from that thread.
Here is a simplified version of what i'm trying to do. If I add the JButton in the init() thread everything works fine, but if I try to do it in the thread that I create nothing happens. From the thread I create I can do things like change the text of the button, but can't seem to add or remove components.
import javax.swing.JApplet;
import javax.swing.JButton;
/**
*
* @author alex
*/
publicclass Mainextends JAppletimplements Runnable{
/** Creates a new instance of Main */
public Main(){
}
publicvoid start(){
Thread t =new Thread(this);
t.start();
}
publicvoid run(){
this.add(new JButton("TEST"));
}
}
If instead of creating my own thread I use SwingUtilities.invokeAndWait this works, but I don't want to run my program in that thread. I've tried using invokeAndWait from the thread I create but that doesn't seem to work.
Anyone have any ideas ?

