import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Calculator
{public static void main(String[] args)
{CalculatorFrame frame=new CalculatorFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
class CalculatorFrame extends JFrame
{public static final int WIDTH=300;
public static final int HEIGHT=300;
public CalculatorFrame()
{setTitle("学生成绩管理系统");
setSize(WIDTH,HEIGHT);
Container contentPane=getContentPane();
CalculatorPanel panel=new CalculatorPanel();
contentPane.add(panel);
}
}
class CalculatorPanel extends JPanel
{private JTextField text1;
private JTextField text2;
private JTextField text3;
private JTextField text4;
private JTextField text5;
private JTextField text6;
private JButton button1;
private JButton button2;
private JButton button3;
private JButton button4;
private JLabel label1;
private JLabel label2;
private JLabel label3;
private JLabel label4;
private JLabel label5;
private JLabel label6;
private JPanel panel;
public CalculatorPanel()
{setLayout(new BorderLayout());
text1=new JTextField();
text2=new JTextField();
text3=new JTextField();
text4=new JTextField();
text5=new JTextField();
text6=new JTextField();
button1=new JButton("存储");
button1=new JButton("删除");
button1=new JButton("查询");
button1=new JButton("排序");
label1=new JLabel("学号:");
label2=new JLabel("年龄:");
label3=new JLabel("名字:");
label4=new JLabel("数学成绩:");
label5=new JLabel("英语成绩:");
label6=new JLabel("数据结构成绩:");
JPanel panel=new JPanel(new GridLayout(8,6));
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(label3);
panel.add(text3);
panel.add(label4);
panel.add(text4);
panel.add(label5);
panel.add(text5);
panel.add(label6);
panel.add(text6);
panel.add(button1);
panel.add(button2);
panel.add(button3);
panel.add(button4);
add(panel,BorderLayout.CENTER);
}
}
错误如下
---------- java ----------
Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1019)
at java.awt.Container.add(Container.java:351)
at CalculatorPanel.<init>(Calculator.java:76)
at CalculatorFrame.<init>(Calculator.java:21)
at Calculator.main(Calculator.java:8)
输出完成 (耗时: 1 秒) - 正常终止
那位帮帮忙
谢谢了