我可以从 java 命令行程序创建 Jframe 对话框并在继续执行主程序之前等待返回吗?
下面的代码不起作用,但这是我的想法。
public static void main(String args[]){
Dialog dl = new DialogGui();
dl.setVisable(true);
while(dl.isVisiabl(){
//wait....
}
}
如果它能够从 Jframe 返回数据,那就更好了。
最佳答案
不要使用JFrame
,使用JDialog
。
有一个你要找的预封装对话框工厂:JOptionPane .它的对话框既是模态的又是阻塞的,直到方法返回。例如,一个确认对话框:
if ( JOptionPane.showConfirmDialog( null, "this is a message",
"this is a title", JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE ) == JOptionPane.YES_OPTION )
{
// do something since the user selected yes
}
对话框可以合理地自定义,请参阅文档。
关于来自主命令行的 Java 模态对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17984202/