我想使用 ArrayList
迭代此表单的字段,但我不知道该怎么做。
这是表单的图像:
这是代码:
private void btnTotalActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
double index=Double.parseDouble(txtIndexNou.getText())- Double.parseDouble(txtIndexVechi.getText());
txtIndexTotal.setText(Double.toString(index));
txtCam1.setText(Double.toString(index));
txtTotal1.setText(Double.toString((index *a)));
double index1=Double.parseDouble(txtIndexNou2.getText())-Double.parseDouble(txtIndexVechi2.getText());
txtIndexTotal.setText(Double.toString(index1));
txtCam1.setText(Double.toString(index1));
txtTotal1.setText(Double.toString((index1 *a)));
double index2=Double.parseDouble(txtIndexNou3.getText())-Double.parseDouble(txtIndexVechi3.getText());
txtIndexTotal.setText(Double.toString(index2));
txtCam1.setText(Double.toString(index2));
txtTotal1.setText(Double.toString((index2 *a)));
double index3=Double.parseDouble(txtIndexNou4.getText())-Double.parseDouble(txtIndexVechi4.getText());
txtIndexTotal.setText(Double.toString(index3));
txtCam1.setText(Double.toString(index3));
txtTotal1.setText(Double.toString((index3 *a)));
double index4=Double.parseDouble(txtIndexNou5.getText())-Double.parseDouble(txtIndexVechi5.getText());
txtIndexTotal.setText(Double.toString(index4));
txtCam1.setText(Double.toString(index4));
txtTotal1.setText(Double.toString((index4 *a)));
}
最佳答案
txtIndexNou 和 txtIndexVechi 我认为它们是某种文本输入,必须使用循环创建并将引用存储在 ArrayList 中,然后当您想读回它们的值时,只需迭代列表即可。
编辑 1
为了优化代码重复,您可以将逻辑封装到方法中。
关于java - 如何将表单字段放入列表中以便能够迭代它们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32247918/