令人头痛的java中的空指针问题

来源:百度知道 编辑:UC知道 时间:2024/07/02 17:01:24
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class jsq extends JFrame implements ActionListener{
String number[]={"1","2","3","4","5","6","7","8","9","0"};
String symbel[]={"+","-","*","/","="};
JButton button[];
JPanel flowpanel,gridpanel;
GridLayout gridlay;
FlowLayout flowlay;
JTextField jtf;
int m=1;
int temp,temp2,result;
String symbel2;
public jsq() {
super("计算器演示程序");
Container c=getContentPane();
flowpanel=new JPanel();
gridpanel=new JPanel();
jtf=new JTextField();
for(int i=0;i<10;i++)
{
button[i]=new JButton(number[i]);
gridpanel.add(button[i]);

String number[]={"1","2","3","4","5","6","7","8","9","0"};
String symbel[]={"+","-","*","/","="};
JButton button[];
JPanel flowpanel,gridpanel;
GridLayout gridlay;
FlowLayout flowlay;
JTextField jtf;
int m=1;
int temp,temp2,result;
String symbel2;
public jsq() {
super("计算器演示程序");
Container c=getContentPane();
flowpanel=new JPanel();
gridpanel=new JPanel();
jtf=new JTextField();
for(int i=0;i<10;i++)
{
button[i]=new JButton(number[i]); //这行出错了
gridpanel.add(button[i]);
button[i].addActionListener(this);
}
for(int j=0;j<5;j++)
{
button[10+j]=new JButton(symbel[j]);
gridpanel.add(button[10+j]);
button[10+j].addActionListener(this);
}
flowpanel.add(jtf);