public class MainApp {
boolean packFrame = false; /**
* Construct and show the application.
*/
public MainApp() {
MainFrame frame = new MainFrame(); //frame.setVisible(true);
// Validate frames that have preset sizes
// Pack frames that have useful preferred size info, e.g. from their layout
if (packFrame) {
frame.pack();
} else {
frame.validate();
} // Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2 ,
(screenSize.height - frameSize.height) / 2); frame.setVisible(true);
} /**
* Application entry point.
*
* @param args String[]
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
//SysUtil.SysInit();
System.out.println("我是你爷爷");
UIManager.setLookAndFeel(UIManager.
getSystemLookAndFeelClassName());
} catch (Exception exception) {
exception.printStackTrace();
} new MainApp();
}
});
}
}这段代码中
if (packFrame) {
frame.pack();
} else {
frame.validate();
} // Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2 ,
(screenSize.height - frameSize.height) / 2);1、这段比较窗体初始化的代码在什么情况下使用,觉得没有也可以啊,我是菜鸟,请大侠指点?2、在这段代码中
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
//SysUtil.SysInit();
System.out.println("我是你爷爷");
UIManager.setLookAndFeel(UIManager.
getSystemLookAndFeelClassName());
} catch (Exception exception) {
exception.printStackTrace();
} new MainApp();
}
});为什么要要用这样一个匿名线程,来实现窗体的的调用??
以上问题比较菜,请大家指点!!
boolean packFrame = false; /**
* Construct and show the application.
*/
public MainApp() {
MainFrame frame = new MainFrame(); //frame.setVisible(true);
// Validate frames that have preset sizes
// Pack frames that have useful preferred size info, e.g. from their layout
if (packFrame) {
frame.pack();
} else {
frame.validate();
} // Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2 ,
(screenSize.height - frameSize.height) / 2); frame.setVisible(true);
} /**
* Application entry point.
*
* @param args String[]
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
//SysUtil.SysInit();
System.out.println("我是你爷爷");
UIManager.setLookAndFeel(UIManager.
getSystemLookAndFeelClassName());
} catch (Exception exception) {
exception.printStackTrace();
} new MainApp();
}
});
}
}这段代码中
if (packFrame) {
frame.pack();
} else {
frame.validate();
} // Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2 ,
(screenSize.height - frameSize.height) / 2);1、这段比较窗体初始化的代码在什么情况下使用,觉得没有也可以啊,我是菜鸟,请大侠指点?2、在这段代码中
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
//SysUtil.SysInit();
System.out.println("我是你爷爷");
UIManager.setLookAndFeel(UIManager.
getSystemLookAndFeelClassName());
} catch (Exception exception) {
exception.printStackTrace();
} new MainApp();
}
});为什么要要用这样一个匿名线程,来实现窗体的的调用??
以上问题比较菜,请大家指点!!
让他去跑完后面的路程 然后自己去做别的事情
和他相对的是SwingUtilities.invokeAndWait 这相当把棒子交给另一个人 让他去跑后面的路
但是还是会等待他跑回来 再去做自己的事情
作用就是异步 想当于搞了个新线程去做另外件事情
2、我也支持这个:如果单独就是这个程序应该是没什么用处的。但是如果程序很大的情况下,有多个任务或是线程在运行的情况,可以防止block线程、死锁之类的问题。