Reputation: 309
I am building an application which helps a user navigate a website by giving step by step instructions.
The instructions are given in the form of dialog boxes. I am using Java Swing to create the GUI dialog boxes.
Here is the structure of my code :
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();
}
}
}
The problem when I run this is that all the 3 instances of the InstructionDialog run simultaneously. So I have all the 3 dialog boxes pop up at the same time.
But I want them to run one after another - the second dialog box should not appear until the OK button of the first is pressed, the third dialog box should not appear until the OK button of the second one is pressed.
How can I achieve this ?
Any help will be appreciated. Thanks.
Upvotes: 0
Views: 2505
Reputation: 91
A time ago I had a similar issue. I developed the small library UiBooster. With UiBooster you can create blocking dialogs to ask the user for different inputs.
String opinion = new UiBooster().showTextInputDialog("What do you think?");
Upvotes: 0
Reputation: 1510
The CardLayout is something I used for similar problems.
It is like a card deck and you can display one after another.
Upvotes: 2