Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我需要按住此窗口,直到按下“完成”按钮:/_Java_Swing_User Interface_Actionlistener - Fatal编程技术网

Java 我需要按住此窗口,直到按下“完成”按钮:/

Java 我需要按住此窗口,直到按下“完成”按钮:/,java,swing,user-interface,actionlistener,Java,Swing,User Interface,Actionlistener,这里的第一个代码来自我无法理解的主代码的prerec boolean CompanyLoaded, StartingNum = true; FirstCheck newwin = new FirstCheck(); public CollectNumbers() { if (StartingNum = true) firstCheck = newwin.FirstCheck(); <----Runs FirstCheck okay if (Comp

这里的第一个代码来自我无法理解的主代码的prerec

boolean CompanyLoaded, StartingNum = true;

FirstCheck newwin = new FirstCheck();

public CollectNumbers() { 

        if (StartingNum = true) firstCheck = newwin.FirstCheck(); <----Runs FirstCheck okay

        if (CompanyLoaded = true) LoadCompany();

不要使用
JFrame-frame=new-JFrame()
使用
JDialog-frame=new-JDialog((frame)null,true)

这将创建一个模式对话框,该对话框将在
frame.setVisible(true)
点阻止代码执行,直到对话框关闭

有关更多信息,请参阅

actionPerformed
方法中,您需要存储一个“返回”值,一旦对话框关闭,应用程序就可以查询该值

public void actionPerformed(ActionEvent e) {
    bnum = false;
    num = Integer.parseInt(NumberEntry.getText());
    Object source = e.getSource();
    if (source instanceof Component) {
        // Close the dialog....
        SwingUtilities.getWindowAncestor((Component)source).dispose();
    }
}
已更新

同样,您也可以使用
JOptionPane
来代替

看看


举几个例子

谢谢你的建议!我会仔细查看你提供的链接@JAKOBBERRY知识是强大的东西,玩得开心;)
public void actionPerformed(ActionEvent e) {
    bnum = false;
    num = Integer.parseInt(NumberEntry.getText());
    Object source = e.getSource();
    if (source instanceof Component) {
        // Close the dialog....
        SwingUtilities.getWindowAncestor((Component)source).dispose();
    }
}