简体   繁体   English

在JTable中获取单元格值

[英]Getting Cell Values in JTable

Anything wrong here? 这里有什么问题吗?

    JButton btnCheckout = new JButton("Checkout");
    btnCheckout.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            racingUsr.setVisible(false);
            int row = 0;
            int col = 4; 
            int price = 0,subtotal = 0,qty = 0,rowin = table.getSelectedRow();

            if(rowin == 0){
            qty = Integer.parseInt(JOptionPane.showInputDialog(null,"How many of that game?"));
            Object a = table.getModel().getValueAt(row, col);
            a = price;
            subtotal = price * qty;

            JOptionPane.showMessageDialog(null, subtotal);
            }
        }               
    });

Table has 5 rows and 1 column (currently, cant add more yet with this error) coming in from the SQL database. 表有5行和1列(当前,无法添加更多但出现此错误)来自SQL数据库。 When i enter '5' in the quantity, it outputs '0' in the subtotal. 当我在数量中输入“ 5”时,小计中将输出“ 0”。 And i also need an extra help for the quantity count, when i buy a game, of course the quantity should decrease but how? 我还需要额外的数量帮助,当我购买游戏时,数量当然应该减少,但是如何? I hope someone can help. 我希望有人能帮帮忙。 TIA. TIA。

Error: 错误:

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1 >= 1

You have a=price; 你有一个价格。 instead of price = a; 而不是价格= a;

This is the reason because you get the 0 in the subtotal. 这是因为小计中得到0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM