这是一个计算机程序 (未完成) (具体程序在下边)
bug 在计算后关闭程序会出现下列异常
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: component argument pData
at sun.awt.windows.Win32SurfaceData.initOps(Native Method)
at sun.awt.windows.Win32SurfaceData.<init>(Unknown Source)
at sun.awt.windows.Win32SurfaceData.createData(Unknown Source)
at sun.awt.Win32GraphicsConfig.createSurfaceData(Unknown Source)
at sun.awt.windows.WComponentPeer.replaceSurfaceData(Unknown Source)
at sun.awt.windows.WComponentPeer.replaceSurfaceData(Unknown Source)
at sun.awt.windows.WComponentPeer$2.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
import java.awt.*;
import java.lang.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import java.io.*;public class Counter extends JApplet implements ActionListener {
private Container   container;
private JPanel      upPanel;
private JPanel      midPanel;
private JPanel[]    panel;
private JTextField  textField;
private JButton[]   button;
private int[]       hash;
private double      sum = 0.0;

private final static int rowPanel = 5;
private final static int colPanel = 1;
private final static int maxSize  = 10000;

public void init () {
container = this.getContentPane();
hashInit();
addTextField();
addPanel();
this.setSize(350, 300);
this.setVisible(true);
this.setLocation(500, 300);
}

public void destroy() {
//this.notifyAll();
System.out.println ("destroy");
}

public void hashInit() {
hash = new int[maxSize];
for (int i = 0; i < 10000; i++) {
hash[i] = -1;
}
for (int i = 0; i < 10; i++) {
hash[i] = i;
}
}

public void addTextField() {
textField = new JTextField(25);
upPanel = new JPanel();
upPanel.add(textField);
container.add(upPanel, BorderLayout.NORTH); }

public void addPanel() {
int row, col, cnt;
String name[] = {new String ("    Backspace    "), new String ("      CE      "), new String ("      C      "),
 new String ("MC"), new String ("7"),    new String ("8"),   new String ("9"), 
 new String ("/"),  new String ("sqrt"), new String ("MR"),  new String ("4"),
 new String ("5"),  new String ("6"),    new String ("*"),   new String ("  %  "),
 new String ("MS"), new String ("1"),    new String ("2"),   new String ("3"),
 new String ("-"),  new String (" 1/x "),  new String ("M+"),  new String ("0"), 
 new String ("+/-"), new String ("."),  new String ("+"),    new String ("  = ")};   

midPanel = new JPanel();
midPanel.setLayout(new GridLayout(rowPanel, colPanel));
container.add(midPanel, BorderLayout.CENTER);
panel  = new JPanel[5];
button = new JButton[31];

try {
for (row = cnt = 0; row < 5; row++) {
 panel[row] = new JPanel();
 midPanel.add(panel[row]);
for (col = 0; col < 6; col++) {
if (row == 0 && col >= 3){
   // label[col - 3] = new JLabel(" ");
//panel[row].add(label[col - 3]);
break;
} else {
button[cnt] = new JButton(name[cnt]);
button[cnt].addActionListener(this);
button[cnt].setSize(10,10);
panel[row].add(button[cnt++]);
}
}

}
} catch (Exception e) {
System.out.println (e.getMessage());
}

}

public double answer (double sum, char opera, String a) {
switch (opera) {
case '*': 
sum *= Double.valueOf(a);
break;
case '/':
sum /= Double.valueOf(a);
break;
case '-':
sum -= Double.valueOf(a);
break;
case '+':
sum += Double.valueOf(a);
default:
sum = Double.valueOf(a);
}
return sum;
}

public void actionPerformed (ActionEvent e) {
String name  = new String (((JButton)e.getSource()).getText());
if (name.length() > 3 && name.charAt(2) == '=') {
sum = 0.0;
String equation = new String (textField.getText());
char   opera = '0';
String tmp     = new String();
tmp = null;

for (int i = 0; i < equation.length(); i++) {
if (equation.charAt(i) >= '0' && equation.charAt(i) <= '9' ||
equation.charAt(i) == '.') {
if (tmp == null) {
tmp = String.valueOf(equation.charAt(i));
} else {
tmp +=  equation.charAt(i);
}
} else {
System.out.println (sum + opera + tmp);
sum = answer (sum, opera, tmp);
System.out.println (sum);
opera = equation.charAt(i);
tmp = null;
}
}
System.out.println (sum + opera + tmp);
sum = answer (sum, opera, tmp);
System.out.println (sum);
if (Math.abs((int)sum  - sum) > 0)
textField.setText(Double.toString(sum));
else 
textField.setText(Integer.toString((int)sum));
//System.exit(0);
} else if (name.charAt(0) - '0' < 0) {
textField.setText(textField.getText() + name);
} else if (hash[name.charAt(0) - '0'] >= 0 && hash[name.charAt(0) - '0'] <= 9) {
if (sum != 0.0) {
sum = 0.0;
textField.setText(String.valueOf(hash[name.charAt(0) - '0']));
} else {
textField.setText(textField.getText() + hash[name.charAt(0) - '0']);
}
}
}
}