Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/375.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 Swing GUI-如何打开多个对话框,一个接一个?_Java_Swing_User Interface_Dialog - Fatal编程技术网

Java Swing GUI-如何打开多个对话框,一个接一个?

Java Swing GUI-如何打开多个对话框,一个接一个?,java,swing,user-interface,dialog,Java,Swing,User Interface,Dialog,我正在构建一个应用程序,通过逐步给出说明来帮助用户浏览网站 说明以对话框的形式给出。我正在使用JavaSwing创建GUI对话框 以下是我的代码结构: MainClass { //some selenium code to access the website 'Google.com'..... InstructionDialog frame1 = new InstructionDialog("Enter 'Hello' in search field"); frame

我正在构建一个应用程序,通过逐步给出说明来帮助用户浏览网站

说明以对话框的形式给出。我正在使用JavaSwing创建GUI对话框

以下是我的代码结构:

MainClass
{
    //some selenium code to access the website 'Google.com'.....

    InstructionDialog frame1 = new InstructionDialog("Enter 'Hello' in search field");
    frame1.setVisible(true);

    InstructionDialog frame2 = new InstructionDialog("Click 'Search' button");
    frame2.setVisible(true);

    InstructionDialog frame3 = new InstructionDialog("'Hello' is displayed in the results");
    frame3.setVisible(true);


}


class InstructionDialog extends JFrame {


    public String message;
    public static javax.swing.JButton btnOk;


    public InstructionDialog(String message)
    {

        //some code for the content pane //

        msgArea = new JTextArea();
        msgArea.setBounds(12, 13, 397, 68);
        contentPane.add(msgArea);
        msgArea.setEditable(false);
        simpleStepMessage.msgArea.setText(message);


        btnOk = new JButton("OK");
        btnOk.setBounds(323, 139, 97, 25);
        contentPane.add(btnOk);
        btnOk.addActionListener(new java.awt.event.ActionListener() 
        {
            public void actionPerformed(java.awt.event.ActionEvent evt) 
            {
                OkBtnActionPerformed(evt);
            }
        });


    public void OkBtnActionPerformed(java.awt.event.ActionEvent evt)
    {
        this.dispose();

    }


    }

}
运行此命令时的问题是,指令对话框的所有3个实例同时运行。因此,我让所有3个对话框同时弹出

但我希望它们一个接一个地运行—第二个对话框在第一个对话框的OK按钮按下之前不应出现,第三个对话框在第二个对话框的OK按钮按下之前不应出现

我怎样才能做到这一点

任何帮助都将不胜感激。谢谢。

这是我用来解决类似问题的工具


它就像一个卡片组,你可以一个接一个地显示。

前一段时间我也遇到过类似的问题。我开发了这个小图书馆。使用UiBooster,您可以创建阻塞对话框,要求用户输入不同的输入

此外,谷歌“摇摆向导”或类似的。下面是使用CardLayout的Oracle官方教程:
String opinion = new UiBooster().showTextInputDialog("What do you think?");