当前位置: 技术问答>java相关
在JBuilder创建一工程?这句什么意思?
来源: 互联网 发布时间:2015-06-17
本文导语: package untitled2; import javax.swing.UIManager; import java.awt.*; public class Application1 { boolean packFrame = false; public Application1() { Frame1 frame = new Frame1(); layout if (packFrame) { frame.pack(); } ...
package untitled2;
import javax.swing.UIManager;
import java.awt.*;
public class Application1 {
boolean packFrame = false;
public Application1() {
Frame1 frame = new Frame1();
layout
if (packFrame) {
frame.pack();
}
else {
frame.validate();
}
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);
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
e.printStackTrace();
}
new Application1();
//请问这什么意思,怎么不是
Application1 sApp=new Application1()?
}
}
import javax.swing.UIManager;
import java.awt.*;
public class Application1 {
boolean packFrame = false;
public Application1() {
Frame1 frame = new Frame1();
layout
if (packFrame) {
frame.pack();
}
else {
frame.validate();
}
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);
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
e.printStackTrace();
}
new Application1();
//请问这什么意思,怎么不是
Application1 sApp=new Application1()?
}
}
|
new Application1(); 这句等价于实例化一个它的对象
它已经让Application1的构造函数开始执行了
没有必要用Application1 sApp=new Application1()来实例化
它已经让Application1的构造函数开始执行了
没有必要用Application1 sApp=new Application1()来实例化
|
没有必要
Application1 sApp=new Application1()
因为构造函数已经把窗口显示出来,而且变量sApp确实没有用
Application1 sApp=new Application1()
因为构造函数已经把窗口显示出来,而且变量sApp确实没有用
|
也就是说,不要产生没必要的浪费。
sApp根本就没什么用
sApp根本就没什么用