设置表格行数出错
我在设置表格行数时,下面相应的一部分内容不见了,请教!import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
class Win extends JFrame implements ActionListener
{
JTable ta;
JButton row,count;
JLabel jb;
Object[][] a;
Object[] name={"语文","数学","英语","总成绩"};
JTextField jtf;
int r=1;
JPanel p;
Win()
{
super("成绩表");
a=new Object[r][4];
row=new JButton("确定");
count=new JButton("总成绩");
jb=new JLabel("请输入行数");
jtf=new JTextField(8);
count.addActionListener(this);
row.addActionListener(this);
p=new JPanel();
p.add(jb);
p.add(jtf);
p.add(row);
p.add(count);
ta=new JTable(a,name);
add(p,BorderLayout.SOUTH);
add(new JScrollPane(ta),BorderLayout.NORTH);
setBounds(200,200,600,260);
setVisible(true);
validate();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==row)
{
r=Integer.parseInt(jtf.getText());
System.out.println(r);
a=new Object[r][4];
ta=new JTable(a,name);
getContentPane().removeAll();
add(new JScrollPane(ta),BorderLayout.NORTH);
add(p,BorderLayout.SOUTH);
validate();
}
}
}
public class Exam820
{
public static void main(String[] ar)
{
new Win();
}
}