3 回答
TA贡献1804条经验 获得超3个赞
testField.getText()
参见Java文档中的JTextField
示例代码可以是:
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
String textFieldValue = testField.getText();
// .... do some operation on value ...
}
})
TA贡献1801条经验 获得超16个赞
* First we declare JTextField like this
JTextField testField = new JTextField(10);
* We can get textfield value in String like this on any button click event.
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
String getValue = testField.getText()
}
})
TA贡献1798条经验 获得超7个赞
我们如何从文本字段中检索值?
mytestField.getText();
ActionListner 例:
mytextField.addActionListener(this);
public void actionPerformed(ActionEvent evt) {
String text = textField.getText();
textArea.append(text + newline);
textField.selectAll();
}
添加回答
举报