java - Java:如何暂停线程执行,直到 JFrame 被释放
问题描述
我需要在 JFrame 的帮助下处理错误情况:
catch (FormatterException e) {
displayJFrame();
System.out.println("Execution continues");
}
基本上,在 JFrame 中,我会手动输入在 textarea 中失败的数据并单击 JButton(为简洁起见,这只是 JFrame 和 JButton):
static void displayJFrame() {
JFrame frame = new JFrame("JFrame recovery window");
// create our jbutton
JButton showDialogButton = new JButton("Submit");
// add the listener to the jbutton to handle the "pressed" event
showDialogButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame.dispose();
}
});
// put the button on the frame
frame.getContentPane().setLayout(new FlowLayout());
frame.add(showDialogButton);
// set up the jframe, then display it
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setPreferredSize(new Dimension(300, 200));
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
我需要的是,当按下 Button 时,会释放框架并继续执行主线程。不幸的是,它不是那样工作的。主线程在处理帧之前打印“执行继续”。有没有办法在 Swing/AWT API 中实现这一点?
谢谢
解决方案
推荐阅读
- css - Powershell - 如何在侧面独家选择文本
- node.js - Node Buffer.lastIndexOf byteOffset 是如何工作的?
- javascript - 尝试以给定角度计算鼠标 x 或 y(或两者的比率)以给出距离
- sql - 组合 SQL 查询结果集以对具有匹配文本值的行求和
- node.js - NodeJs从变量上的异步获取返回数据以重用
- android - 如何在片段上使用 SupportFragmentManager
- r - While 循环采样,直到对象采用选择值之一
- r - 从数据框中查找男性和女性的百分比
- python - 悉尼的 Choropleth 地图
- javascript - 退货有错误(我不明白为什么