程序是
package PersonalCAC;import javax.swing.UIManager;
import java.awt.*;public class Application1 {
boolean packFrame = false;
Application1 application1;
/**Construct the application*/
public Application1() {
Frame1 frame = new Frame1(); //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);
}
/**Main method*/
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
e.printStackTrace();
}
new Application1();
}
}
package PersonalCAC;import javax.swing.UIManager;
import java.awt.*;public class Application1 {
boolean packFrame = false;
Application1 application1;
/**Construct the application*/
public Application1() {
Frame1 frame = new Frame1(); //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);
}
/**Main method*/
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
e.printStackTrace();
}
new Application1();
}
}
出现: java.lang.NullPointerException 说明你的frame是一个空值.但问题是你已经初始化了frame:
JFrame1 frame=new JFrame1();
那么现在问题就应该归到JFrame1类身上...
(在类JFrame1中的构造器中是否调用了超类构造器?)