[英]How to call some method from different variables that from same Object?
I have some TextField, when user clicks Submit Button my program will send its data to JavaDB. 我有一些TextField,当用户单击Submit Button时,我的程序会将其数据发送到JavaDB。 After that, the program will set all TextField to be empty. 之后,程序将所有TextField设置为空。 I am using this code: 我正在使用此代码:
nama.setText("");
jenis.setText("");
bendera.setText("");
tujuan.setText("");
pelabuhanTerakhir.setText("");
latitude.setText("");
longitude.setText("");
area.setText("");
kecepatan.setText("");
haluan.setText("");
status.setText("");
keterangan.setText("");
waktu.setText(formattedDate_);
Is there any way to do that to make my code more efficient in Java? 有没有办法让我的代码在Java中更高效?
You could put your TextFields inside a list. 您可以将TextField放在列表中。 Then iterate with the help of an for each loop through this list, and invoke every time on the current entry the method setText(""). 然后在每个循环的帮助下通过此列表进行迭代,并在每个当前条目上调用方法setText(“”)。
You can make an array of TextFields and then go through it with a for loop, each time invoking setText(""). 您可以创建一个TextField数组,然后使用for循环遍历它,每次调用setText(“”)。 For example: 例如:
for(int i=0; i<yourTextFieldArray.length; i++) {
yourTextFieldArray[i].setText("");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.