[英]How to click on a button to make a program wait
My code is like this:↓ 我的代码是这样的:↓
JButton button = new JButton("TEXT");
button.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e){
object.wait();
}
}
When I click on this button, the window is dead and I have to terminate the program in task manager... 当我单击此按钮时,窗口已死,我必须在任务管理器中终止程序...
So...basically can I add a object.wait() in mouselistener? 所以...基本上我可以在mouselistener中添加object.wait()吗?
Thank you all! 谢谢你们!
Then, if I run my GUI on a separate thread, how to make the program...(I'm sorry I self-studied the multi-thread part of JAVA so I'm a little bit confused right now) 然后,如果我在单独的线程上运行GUI,如何制作程序...(很抱歉,我自学了JAVA的多线程部分,所以现在有点困惑了)
1.when I click on a button, it will pause and wait for my input in GUI 1.当我点击一个按钮时,它将暂停并等待我在GUI中的输入
2.when I click on another button, the program continues... 2.当我单击另一个按钮时,程序继续...
when I click on a button, it will pause and wait for my input in GUI
当我单击一个按钮时,它将暂停并等待我在GUI中的输入
Use a JOptionPane (or a modal JDialog) to get user input. 使用JOptionPane(或模式JDialog)获取用户输入。 Read the section from the Swing tutorial on How to Make Dialogs for more information and examples.
阅读Swing教程中有关如何制作对话框的部分, 以获取更多信息和示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.