帮忙看看,查了很久不知道错在哪里?
想点按钮"总成绩"就在算出英语各数学的成绩,并在第四栏中显示,但就是显示不出来,帮忙看看!
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
class Win extends JFrame implements ActionListener
{
JTable jtb;
JTextField jtf;
JButton addc;
JButton count;
Object name[]={"姓名","英语","数学","总成绩"};
Object a[][];
int row=1;
JPanel p;
Win()
{
jtf=new JTextField(10);
addc=new JButton("增加");
count=new JButton("总成绩");
addc.addActionListener(this);
count.addActionListener(this);
a=new Object[row][4];
jtb=new JTable(a,name);
p=new JPanel();
p.setSize(400,160);
p.add(new JLabel("输入表格的行数:"));
p.add(jtf);
p.add(addc);
p.add(count);
add(p,BorderLayout.SOUTH);
add(new JScrollPane(jtb),BorderLayout.CENTER);
setSize(550,220);
setVisible(true);
validate();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==addc)
{
row=Integer.parseInt(jtf.getText());
a=new Object[row][4];
jtb=new JTable(a,name);
getContentPane().removeAll();
add(new JScrollPane(jtb),BorderLayout.CENTER);
add(p,BorderLayout.SOUTH);
validate();
}
else if(e.getSource()==count)
{
for(int i=0;i<row;i++)
{
double sum=0;
boolean boo=true;
for(int j=0;j<=2;j++)
{
try
{
sum=sum+Double.parseDouble(a[i][j].toString());
}
catch(Exception ex)
{
boo=false;
repaint();
}
if(boo==true)
{
a[i][3]=""+sum;
jtb.repaint();
}
}
}
}
}
}
public class Exam815
{
public static void main(String[] arg)
{
new Win();
}
}