【发布时间】:2023-03-18 03:11:01
【问题描述】:
我正在构建一个应用程序,通过提供分步说明帮助用户浏览网站。
说明以对话框的形式给出。我正在使用 Java Swing 创建 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();
}
}
}
我运行它时的问题是 InstructionDialog 的所有 3 个实例同时运行。所以我同时弹出了所有 3 个对话框。
但我希望它们一个接一个地运行——直到按下第一个对话框的 OK 按钮后才会出现第二个对话框,直到按下第二个对话框的 OK 按钮后才会出现第三个对话框。
我怎样才能做到这一点?
任何帮助将不胜感激。谢谢。
【问题讨论】:
标签: java swing user-interface dialog