I'm somewhat new to the world of JApplets (or just Applets) and I've noticed in my research that almost all examples like to create the contents of the JApplet as a function of adding it to the Event Dispatch Thread. For example, I'm currently looking at this:
public void init() { //Execute a job on the event-dispatching thread: //creating this applet's GUI. try { [b]javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { createGUI(); } });[/b] } catch (Exception e) { System.err.println("createGUI didn't successfully complete"); } }
private void createGUI() { JLabel label = new JLabel( "You are successfully running a Swing applet!"); label.setHorizontalAlignment(JLabel.CENTER); label.setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.black)); getContentPane().add(label, BorderLayout.CENTER); }
I'm just wondering why this is necessary. What does it do that something more simple (say just putting the code in createGUI() right into the init() function, replacing the try block) wouldn't do?
I have some follow up questions but we'll start with this one.