弱弱的一个问题!100分 !!
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();
}
});
为什么要要用这样一个匿名线程,来实现窗体的的调用??
以上问题比较菜,请大家指点!!