获取JTextField的值,其名称存储在JAVA中的String变量中

时间:2016-05-30 15:27:57

标签: java

场景:

public class frame1 extends javax.swing.JFrame { 

 public void processName(){
 String n1 = "txtName";
 JOptionPane.showMessageDialog(null,"**here i want to show the value from the JTextField using String Variable n1 ,just like we do txtName.getText()**");
 }

 private javax.swing.JTextField txtName;
}

我知道上面的问题很奇怪,但我所处的情况,我必须找到其他方法。如果有任何解决方案,请告诉我。 感谢。

注意:我只粘贴了上面的相关代码。请假设我在Button click事件上调用processName()函数。

编辑: 确切的问题是:我有一个与数据库字段名称完全相同的JTextField列表。 现在,我想使用while循环使用数据库中的数据填充这些JTextField。它们很多。所以我不想更改JTextfield名称或数据库字段名称。

0 个答案:

没有答案