JOptionPane.showConfirmDialog(null, instructorEditorPanel,
"Edit Player JOptionPane", JOptionPane.OK_CANCEL_OPTION,JOptionPane.PLAIN_MESSAGE);
instructorEditorPanel 是一个具有 3 个文本字段的 Jpanel。我试图获取文本字段中的数据并将它们分配给父类中的实例变量。我知道如何使用 getText() 方法获取数据。我的问题是在选择“确定”按钮时操纵处理程序执行操作。
最佳答案
在这种情况下,当单击“确定”按钮时,showConfirmDialog() 将返回 0。你可以这样做:
if(JOptionPane.showConfirmDialog(null, instructorEditorPanel, "Edit Player JOptionPane", OptionPane.OK_CANCEL_OPTION,JOptionPane.PLAIN_MESSAGE) == JOptionPane.OK_OPTION){
//do something with value
fieldOnPanel.getText();
}
显然,您需要有权访问 JPanel 或 JTextField 实例。
关于java - 尝试获取 actionPerformed 上的 textField 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10195800/