当前位置: 代码迷 >> Java相关 >> 帮忙看看,查了很久不知道错在哪里?
  详细解决方案

帮忙看看,查了很久不知道错在哪里?

热度:379   发布时间:2008-03-06 15:33:18.0
帮忙看看,查了很久不知道错在哪里?
想点按钮"总成绩"就在算出英语各数学的成绩,并在第四栏中显示,但就是显示不出来,帮忙看看!
搜索更多相关的解决方案: 英语  数学  总成绩  按钮  

----------------解决方案--------------------------------------------------------
你的代码呢?
----------------解决方案--------------------------------------------------------
发代码啊  兄弟
----------------解决方案--------------------------------------------------------
什么都没,人怎么帮你看啊
----------------解决方案--------------------------------------------------------
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();
    }
}
----------------解决方案--------------------------------------------------------
不好意思,有点急事!
----------------解决方案--------------------------------------------------------
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)
        {  
             System.out.println("您点了汇总按钮");      
            for(int i=0;i<a.length;i++)
            {   
            //System.out.println("您点了汇总按钮"+i);
                double sum=0;
                boolean boo=true;
                for(int j=1;j<a[i].length-1;j++)
                {
                    try
                    {
                        sum=sum+Double.parseDouble(a[i][j].toString());//问题在这
                    }
                    catch(Exception ex)
                   {
                        boo=false;
                       repaint();
                   }
                    
                }
                if(boo==true)
                   {
                        //System.out.println("您点了汇总按钮2");
                        a[i][3]=sum;
                        jtb.repaint();
                   }
             }
            
            
        }
    }
   
}
public class Exam815
{
    public static void main(String[] arg)
    {
        new Win();
    }
}
在标签上输入成绩的时候,输入好后,一定把光标移开....我检测了错误
try
                    {
                        sum=sum+Double.parseDouble(a[i][j].toString());
                    }
                    catch(Exception ex)
                    {
                        boo=false;
                        repaint();
                    }
这里有错误的话就没有结果了....

[[it] 本帖最后由 sunkaidong 于 2008-3-7 09:07 编辑 [/it]]
----------------解决方案--------------------------------------------------------
好象你的程序有很多地方要改,
好象输入了姓名就 不能计算,有很多问题
----------------解决方案--------------------------------------------------------
  相关解决方案