[英]Receiving input from JTextField
I'm have a grid of textfields and labels and i want to know what would i have to do to get the input from the textfields. 我有一个文本字段和标签的网格,我想知道我要怎么做才能从文本字段中获取输入。 I know how to do it if it was declared?
我知道如何声明它吗? i think is the word for it, but this is a bit different.
我认为是这个词,但这有点不同。 i dont know how to recieve the input from something that hasnt been given a name.
我不知道如何从尚未命名的内容中接收输入。 this was something i realized after the matter.
这件事我后来才意识到。
A sample from a class of what i'm talking about 我正在说的一类例子
for (int c = 0; c < 9; c++) {
p3 = new JPanel(new GridLayout(3, 3));
p3.setBorder(lineBorder);
for (int d = 0; d <= 8; d++) {
if (d == 0) {
p3.add(new JLabel("5", JLabel.CENTER));
} else if (d == 5) {
p3.add(new JLabel("8", JLabel.CENTER));
} else if (d == 7) {
p3.add(new JLabel("2", JLabel.CENTER));
} else {
p3.add(new JTextField(1));
}
}
}
Declare a List
before the for
loop and change the else statement to 在
for
循环之前声明一个List
并将else语句更改为
else {
JTextField tf = new JTextField(1);
list.add(tf);
p3.add(tf);
}
After that iterate over the list
and get the text from each element. 之后,遍历
list
并从每个元素获取文本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.