簡體   English   中英

在JTable中獲取單元格值

[英]Getting Cell Values in JTable

這里有什么問題嗎?

    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);
            }
        }               
    });

表有5行和1列(當前,無法添加更多但出現此錯誤)來自SQL數據庫。 當我在數量中輸入“ 5”時,小計中將輸出“ 0”。 我還需要額外的數量幫助,當我購買游戲時,數量當然應該減少,但是如何? 我希望有人能幫幫忙。 TIA。

錯誤:

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

你有一個價格。 而不是價格= a;

這是因為小計中得到0。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM