我有一个简单的问题,为什么我需要写类似以下格式的代码:
SwingUtilities.invokeLater(new Runnable(){
如果程序没有使用它,是否可以创建相同的框架?
使用SwingUtilities编写的代码。
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class App {
public static void main (String args[]){
SwingUtilities.invokeLater(new Runnable(){
public void run() {
JFrame frame = new JFrame("Hello world swing");
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 400);
}
});
}
}
不使用Swing工具编写的代码。
import javax.swing.JFrame;
public class App {
public static void main (String args[]){
JFrame frame = new JFrame("Hello world swing");
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 400);
}
}