【发布时间】:2013-11-11 15:45:17
【问题描述】:
我希望我的自定义消息类的行为方式与以下 sn-p 中的 JOptionPane 相同:
int reply = JOptionPane.showConfirmDialog(
null,
"Is the weather beautifull?",
"Question",
JOptionPane.YES_NO_OPTION
);
if (reply == JOptionPane.YES_OPTION) {
// do something in response to yes...
} else {
// do something in response to no...
}
所以我真正想要的是,我创建自己的消息对象,显示它并在用户按下按钮时做出反应,伪代码如下:
show my question message;
wait for user button press without blocking UI thread;
do something depending on which button the user pressed;
我尝试了所有方法让我的消息框像 Futures、Wait/Notify 等的 JOptionPane 一样,但我总是以在阻止我的 UI 线程。
JOptionPane 这样做的秘诀是什么? :)
【问题讨论】:
标签: java multithreading swing wait joptionpane