所以我有一个用 NetBeans/Java 设计的库存管理系统。 它看起来像这样:
当我单击表中的任何项目时,如上所示,文本字段会自动填充,但是我也在考虑获取我单击的任何产品的总成本来计算:
我的意思是,上面点击的产品 (ID 6) 目前有 10 个库存,价格为 15,因此“库存单位总成本”字段中的答案应该是 (150)。
我的问题是,有没有一种简单的方法可以通过 Java 代码来做到这一点,例如将两个 Jtextfields 相乘?或者是否可以在我的数据库中创建另一列来计算总数(如果可能的话)并将其显示在所需的字段中?
感谢所提供的任何帮助。
最佳答案
My question is, is there an easy way to do this via the Java Code, for example multiplying the two Jtextfields together?
是的,这很简单,举个例子:
double units = Double.parseDouble(jTextfield1.getText());
double unitPrice = Double.parseDouble(jTextfield2.getText());
double total = units * unitPrice;
jTextfield3.setText(total);
Or is it possible to create another column in my database to calculate the total (if that's even possible) and display it in the desired field?.
是的,您也可以这样做,但在 java 中计算(以编程方式)比计算查询容易。
关于java - 将两个 JTextField 相乘以显示答案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44239695/