I guess this is a
thread issue. See this simple JApplet
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.SwingUtilities;
public class SimpleJApplet extends JApplet {
public void init() {
try {
GUIThread guiThread = new GUIThread();
SwingUtilities.invokeLater(guiThread);
} catch (Exception e) {
e.printStackTrace();
}
}
public void createGUI() {
getContentPane().add(new JButton("Button Two"));
}
class GUIThread implements Runnable {
public void run() {
createGUI();
}
}
}
It displays the GUI in the browser after first loaded, when I refresh the page. Sometimes it displays sometimes not.
import javax.swing.JApplet;
import javax.swing.JButton;
public class SimpleJApplet2 extends JApplet {
public void init() {
getContentPane().add(new JButton("Button One"));
}
}
But using event dispatching thread is recommended. What is wrong with the first piece of code?
[ November 19, 2004: Message edited by: Xinyi Zhang ]