gpt4 book ai didi

java - 在Java中获取行单元格中的总数

转载 作者:行者123 更新时间:2023-11-30 08:50:14 24 4
gpt4 key购买 nike

<分区>

enter image description here

我在上面创建了一个演示。 JTable 从 MySQL 数据库中检索“ID”、“Name”和“Cost”。用户可以在“折扣”中输入数量 (Qty) 和折扣价格。

当用户按下键盘上的 TAB 键移动到下一个单元格时,我想在“总计”中显示总计。

总计必须是(成本*数量)-折扣

我该如何实现?

我找到了解决方案:

String sql = "select ItemID,ItemName,CostPrice from druginfo where ItemID=?";
try {
pst=conn.prepareStatement(sql);
pst.setString(1, temp);

rs=pst.executeQuery();
addDataToTable(tableSale,DbUtils.resultSetToTableModel(rs));

IDcombo.setSelectedItem(null);
Namecombo.setSelectedItem(null);
exptxt.setText(null);
instock.setText(null);

//getting user input for selling qty
String Qty=JOptionPane.showInputDialog("Insert Selling Quantity :");
double sellingqty=Double.parseDouble(Qty);
//setting qty input value to table sale
tableSale.getModel().setValueAt(sellingqty,i, 3);

//getting user input for specific item discount
String discount = JOptionPane.showInputDialog("Insert Item Discount");
double idiscount=Double.parseDouble(discount);
//setting input value to table sale
tableSale.getModel().setValueAt(idiscount,i, 4);

//getting item cost from the table sale
double icost =(double) tableSale.getModel().getValueAt(i,2);

//calculating Gross Total
double grosstotal = (sellingqty*icost)-idiscount;

//setting grosstotal value to table sale
tableSale.getModel().setValueAt(grosstotal,i, 5);

String invoice = InvoiceNo_txt.getText();
String id = (String) tableSale.getValueAt(i, 0);
String name = (String) tableSale.getValueAt(i, 1);
double dcost = (double) tableSale.getValueAt(i, 2);
String cost = String.valueOf(dcost);//converting double to string
double dqty = (double) tableSale.getValueAt(i, 3);
String qty = String.valueOf(dqty);//converting double to string
double ditemDiscount = (double) tableSale.getValueAt(i, 4);
String itemDiscount = String.valueOf(ditemDiscount);//converting double to string
double dgrossTotal = (double) tableSale.getValueAt(i, 5);
String grossTotal = String.valueOf(dgrossTotal);//converting double to string

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com