gpt4 book ai didi

java - 在按钮中添加总计

转载 作者:行者123 更新时间:2023-12-02 07:17:26 26 4
gpt4 key购买 nike

我在按钮中添加代码时遇到一些问题,例如:我在数量上输入 2,它将 * 价格和数量示例 400 * 2 = 800,但是当我再次输入 2 时,意味着 800 x 2 = 1600,任何人都可以吗?引导我?谢谢,错误显示在最后两行。
` private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
int id = Integer.parseInt(jTextField1.getText()); int qty = Integer.parseInt(jTextField2.getText());

        purchasecontroller.PurchaseProduct(id, qty);
String getname = displaycontroller.SearchbyProductName(id);
jLabel4.setText( "" + getname );
jLabel3.setText("" + qty);
jList1.addElement(getname + qty);
// jList1.add(new Product("Hello", 1));
String getprice = displaycontroller.SearchbyProductPrice(id);
int total = qty * Integer.parseInt (getprice);
jLabel11.setText("" + total );
int finals = (total * qty);
jLabel12.setText("" + finals );
}

`

最佳答案

应该是

int total = qty * Integer.parseInt (getprice);

而不是

int total = qty * getprice;

关于java - 在按钮中添加总计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14756481/

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