The Artima Developer Community
Sponsored Link

Java Answers Forum
Question about running JApplets in Event Dispatch Thread

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Gibran Shah

Posts: 27
Nickname: gibby
Registered: Jun, 2004

Question about running JApplets in Event Dispatch Thread Posted: Jun 18, 2010 1:17 PM
Reply to this message Reply
Advertisement
Hello,

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);
}


found at http://java.sun.com/docs/books/tutorial/uiswing/components/applet.html.

The bold text is the key piece of code.

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.

Thanks for any forthcoming replies.

Topic: distributed .jat doesn't work Previous Topic   Next Topic Topic: urgent help pls.....

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use