我不会得到Jtable列值的总和(int + float)

时间:2017-09-19 04:47:16

标签: java jtable

我不会从用户输入中获取int值和浮动值并计算它并显示给Jlabel我该怎么做? 我用这段代码 -

public int getsum(){

    int sum = 0;
    float Sum = 0;
    for (int i=0; i<jTable2.getRowCount(); i++)
    {
       sum += Integer.parseInt(jTable2.getValueAt(i, 4).toString().trim());
    }
    for (int I=0; I<jTable2.getRowCount(); I++)
    {
       Sum += Integer.parseInt(jTable2.getValueAt((int) I, 4).toString().trim());
    }
    txt_Total_amount.setText(Integer.toString((int) (sum+Sum)));  
    return 0;
}

我的列数据在int中有一些值,有些是浮点数据 所以我试着把这些值的总和加到jLable

在这种情况下,我有这样的错误 -

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "655.5"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:580)
    at java.lang.Integer.parseInt(Integer.java:615)
    at bankapplication.Register_customer.getsum(Register_customer.java:75)
    at bankapplication.Register_customer.jButton5ActionPerformed(Register_customer.java:783)
    at bankapplication.Register_customer.access$800(Register_customer.java:27)
    at bankapplication.Register_customer$9.actionPerformed(Register_customer.java:496)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)........
请帮助我解决问题 给我一个 示例 感谢

0 个答案:

没有答案