从JTextField&获取值将其重新写入现有变量。
示例:
public class variables{
String var = "hi";
public static void main(String[]args){
//do sth
}
}
然后接口读取主类&的值。更改JTextField的值
private void changeVariableActionPerformed(java.awt.event.ActionEvent evt) {
variables.var = txtField.getText();
//then into textfield we write bye & variables.var takes the value of bye
//variables.var = "bye"
}
我想用动作执行
更改var的值答案 0 :(得分:2)
将ActionLister
添加到JTextField
,每次更改值时都会将其指定给您变量。
txtField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
variables.var = txtField.getText();
}
});