郁闷死了!为什么不能这样初始化按钮!
飞行的兔子 2004-09-08 03:45:10 import javax.swing.JApplet;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/*
* Created on 2004-9-8
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
/**
* @author Administrator
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class Calculator extends JApplet {
JPanel p1,p2;
JButton Calkey[];
JTextArea result;
JLabel show;
String[] Signs={"1","2","3","4","5","6","7","8","9","0","/","*","-","+",".","sqrt","%","1/x","="};
String S="";
public Calculator(){
setSize(400,300);
show();
}
public void init(){
p1=new JPanel();
show=new JLabel("result:");
result=new JTextArea(1,15);
p1.add(show);
p1.add(result);
p2=new JPanel();
p2.setLayout(new GridLayout(4,5));
Container c=getContentPane();
c.setLayout(new BorderLayout());
for(int i=0;i<Signs.length;i++){
Calkey[i]=new JButton(Signs[i]);//程序总是报告这行有空指针异常
p2.add(Calkey[i]);
}
c.add(BorderLayout.NORTH,p1);
c.add(BorderLayout.SOUTH,p2);
}
}
为什么有这样的错误呢???我觉得没问题啊!