|
In jdk5.0 sun, in order to ensure that the GUI code is created from a thread other than the event dispatch thread, it is recommended to use two methods defined by the SwingUtilties class: invokeAndWait () or invokeLater (), such as:
import java.awt. *;
import javax.swing. *;
public class JLabelDemo extends JApplet {
public void init ()
try {
SwingUtilites.invokeAndWait (
new Runnable () {
public void run () {
makeGUI ();
}
}
);
} catch (Exception e) {
System.out.println ("Can't create" + e);
}
}
private void makeGUI () {
ImageIcon ii = new ImageIcon ("xxx.gif");
JLabel jl = new JLabel ("France", ii, JLabel.CENTER);
add (jl);
}
}
_____________________________________________________________
Could you write it as:
Synchronized private void makeGUI () {
While not using nvokeAndWait () ??? / |
|