JTextField创建了二维数组 但一直报错空指针 求大神解答
JTextField[][]scores=newJTextField[10][6];for(inti=0;i<scores.length;i++){for(intj=0;...
JTextField[][] scores= new JTextField[10][6];
for(int i=0;i<scores.length;i++){
for(int j=0; j<scores[i].length;j++){
scores[i][j]=new JTextField("默认");
}
}
JPanel p1=new JPanel();
p1.setLayout(new GridLayout(11,6,0,0));
p1.add(new JLabel("姓名"));
DataInputStream Input1 = new DataInputStream(new FileInputStream("a.txt"));
try{while(true)
{p1.add(new JLabel(Input1.readUTF()));
}
}
catch(EOFException ex){
}
for(int i=0;i<scores.length;i++){
for(int j=0; j<scores[i].length;j++){
p1.add(scores[i][j]);
}
}
add(p1);
JPanel p2=new JPanel(new GridLayout(1,3,10,10));
JButton a=new JButton("确认");
JButton b=new JButton("返回");
JButton c=new JButton("继续添加");
p2.add(a);
p2.add(b);
p2.add(c);
add(p1,BorderLayout.CENTER);
add(p2,BorderLayout.SOUTH);
a.addActionListener(new ButtonListener());
b.addActionListener(new bListener());
c.addActionListener(new cListener()); 展开
for(int i=0;i<scores.length;i++){
for(int j=0; j<scores[i].length;j++){
scores[i][j]=new JTextField("默认");
}
}
JPanel p1=new JPanel();
p1.setLayout(new GridLayout(11,6,0,0));
p1.add(new JLabel("姓名"));
DataInputStream Input1 = new DataInputStream(new FileInputStream("a.txt"));
try{while(true)
{p1.add(new JLabel(Input1.readUTF()));
}
}
catch(EOFException ex){
}
for(int i=0;i<scores.length;i++){
for(int j=0; j<scores[i].length;j++){
p1.add(scores[i][j]);
}
}
add(p1);
JPanel p2=new JPanel(new GridLayout(1,3,10,10));
JButton a=new JButton("确认");
JButton b=new JButton("返回");
JButton c=new JButton("继续添加");
p2.add(a);
p2.add(b);
p2.add(c);
add(p1,BorderLayout.CENTER);
add(p2,BorderLayout.SOUTH);
a.addActionListener(new ButtonListener());
b.addActionListener(new bListener());
c.addActionListener(new cListener()); 展开
1个回答
2013-12-18
展开全部
JTextField[][] scores= new JTextField[10][6];
要放到类变量,不要放在方法、构造里面
要放到类变量,不要放在方法、构造里面
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询