我正在开发一个 java applet 应用程序,我的目标是在另一个弹出窗口(如 confirmDialogWindow)中以用户选择的方法执行或不执行某些操作。现在我遇到了弹出窗口中的热键不起作用的问题。
我知道这是因为打开一个弹出窗口是一个 UI 更新线程,我尝试了诸如invokeLater和invokeAndWait之类的事情来订购事件,热键工作。但是我的方法是根据这个弹出窗口的返回值来确定要执行哪个控制流,如果它在invokeLater方法中,我无法获得正确的返回值。
我该如何解决这个问题?
public class SimpleDialogFrame extends JFrame {
// Using a standard Java icon
private Icon optionIcon = UIManager.getIcon("FileView.computerIcon");
// Application start point
public static void main(String[] args) {
JFrame frame = new JFrame("Sample frame");
frame.setSize(400, 400);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
int confirmNo =0 ;
// Use the event dispatch thread for Swing components
// EventQueue.invokeLater(new Runnable()
// {
// public void run()
// {
// create GUI frame
confirmNo = JOptionPane.showConfirmDialog(frame,
"Is this comfirmed?", "This is the dialog title",
JOptionPane.WARNING_MESSAGE, JOptionPane.YES_NO_OPTION);
// }
// });
if (confirmNo == 0) {
// do something
System.out.println("Clicked OK button");
}
else
{
// do something
}
}
}