cxc3980
发贴: 14
积分: 0
|
于 2006-05-11 19:35
程序如下: import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.border.*; import java.util.LinkedList; import java.text.NumberFormat; public class Calculate extends JFrame implements ActionListener { NumberButton numberButton[]; OperationButton operationButton[]; JButton dotButton,deButton,signButton,recButton,equalsignButton,resetButton; JPanel panel; JTextField resultShow; JLabel label; String operation[]={"+","-","*","/"}; LinkedList linkedList; boolean PequalsignButton=false; /** Creates a new instance of Calculate */ public Calculate() { linkedList=new LinkedList(); numberButton=new NumberButton[10]; for(int i=0;i<=9;i++){ numberButton[i]=new NumberButton; numberButton[i].addActionListener(this); } operationButton=new OperationButton[4]; for(int i=0;i<3;i++){ operationButton[i]=new OperationButton(operation[i]); operationButton[i].addActionListener(this); } dotButton=new JButton("."); deButton=new JButton("de"); signButton=new JButton("+/-"); recButton=new JButton("1/x"); equalsignButton=new JButton("="); resetButton=new JButton("reset"); dotButton.setForeground(Color.blue); deButton.setForeground(Color.blue); signButton.setForeground(Color.blue); recButton.setForeground(Color.blue); equalsignButton.setForeground(Color.blue); resetButton.setForeground(Color.blue); dotButton.addActionListener(this); deButton.addActionListener(this); signButton.addActionListener(this); recButton.addActionListener(this); equalsignButton.addActionListener(this); resetButton.addActionListener(this); resultShow=new JTextField(10); resultShow.setHorizontalAlignment(JTextField.RIGHT); resultShow.setForeground(Color.blue); resultShow.setFont(new Font("TimesRoman",Font.PLAIN,14)); resultShow.setBorder(new SoftBevelBorder(BevelBorder.LOWERED)); resultShow.setBackground(Color.white); resultShow.setEditable(false); panel=new JPanel(); panel.setLayout(new GridLayout(4,5)); panel.add(numberButton[1]); panel.add(numberButton[2]); panel.add(numberButton[3]); panel.add(operationButton[0]); panel.add(resetButton); panel.add(numberButton[4]); panel.add(numberButton[5]); panel.add(numberButton[6]); panel.add(operationButton[1]); panel.add(deButton); panel.add(numberButton[7]); panel.add(numberButton[8]); panel.add(numberButton[9]); panel.add(operationButton[2]); panel.add(recButton); panel.add(numberButton[0]); panel.add(signButton); panel.add(dotButton); panel.add(operationButton[3]); panel.add(equalsignButton); add(panel,BorderLayout.CENTER); add(resultShow,BorderLayout.NORTH); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setVisible(true); setBounds(100,50,240,180); setResizable(false); validate(); }
public void actionPerformed(ActionEvent actionEvent) { } public static void main(String args[]){ new Calculate(); } } 运行后提示如下的错误: java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:625)
at java.awt.Container.add(Container.java:307)
at Calculate.<init>(Calculate.java:96)
at Calculate.main(Calculate.java:117)
Exception in thread "main"
Java Result: 1 请问是什么原因阿?
|