Java 无法将文本框值相乘为第三个
我目前正在开发一个简单的程序来显示数据库的内容。我不知道如何让两个文本框值相乘,然后将结果放入第三个文本框。这是代码的一部分:Java 无法将文本框值相乘为第三个,java,Java,我目前正在开发一个简单的程序来显示数据库的内容。我不知道如何让两个文本框值相乘,然后将结果放入第三个文本框。这是代码的一部分: private void GetProductTable() { ResultSet rs = GetProducts(); try { jTable2.setModel(buildTableModel(rs)); } catch (Exception ex) { } jTable2.addMouseListe
private void GetProductTable() {
ResultSet rs = GetProducts();
try {
jTable2.setModel(buildTableModel(rs));
} catch (Exception ex) {
}
jTable2.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
JTable target;
target = (JTable) e.getSource();
int row;
row = target.getSelectedRow();
String[] result;
result = getRowAt(target, row);
ProductID.setText(result[0]);
ProductName.setText(result[1]);
ProductSupplierID.setText(result[2]);
ProductCataID.setText(result[3]);
ProductInStock.setText(result[4]);
ProductOnOrder.setText(result[5]);
ProductReorderLvl.setText(result[6]);
ProductDiscon.setText(result[7]);
ProductUnitPrice.setText(result[8]);
ProductUnitPrice1.setText();
}
});
}
我需要结果[5]乘以结果[8],然后将总数放入ProductUnitPrice1。正在从外部数据库检索结果。我已经尝试了一些东西,但我就是不能让它工作,我一直得到的是内容或结果5和8都放在盒子里。我知道我需要让它以整数而不是字符串的形式查看结果,但我尝试过的一切都没有奏效
这可能是一个非常简单的解决方案,但我是一个初学者,我需要它来工作,以便在HND中通过Java单元
任何帮助都将不胜感激
int result=Integer.valueOf(result[5])*Integer.valueOf(result[8]);
ProductUnitPrice1.setText(result);
您可能需要将数据类型更改为双精度。也许这也行:
ProductUnitPrice1.setText(String.valueOf(Integer.valueOf(result[5])*Integer.valueOf(result[8])));
“我试过一些东西”。你试过什么?我从你的问题中假设
result
包含字符串,对吗?您是否尝试过使用类似于Double.parseDouble(结果[5])
的方法将它们转换为数字?