I have 3 class, 1 for abstract(named Voter) ,1 for the gui components(named LayOut) and 1 for main(named Election).

On my main I created an object of the gui class and set the visibility to true and the usual stuffs.

but the problem is, on my main I have a JOptionPane code after my gui stuff and every time the Jframe executes the main continues to read the next code after the gui, which is the JOptionPane. I want the JOptionPane to wait for the JFrame's submit button to be clicked before it executes.

here is the pic http://www.daniweb.com/forums/attachment.php?attachmentid=22373&stc=1&d=1316921636
the JFrame and the JOptionPane runs at the same time

I try having a statement on my submit button's actionlistener that says Voter.setEndGui(true);(The initial value of this is false)

and in my main i put an if statement before the JOptionpane stuffs. so the main will not immediately read them on runtime, it must wait for the submit button to be click and validate if Voter.isEndGui()==true;

if(Voter.isEndGui()==true){//like this
//JOptionPane stuff here


but that never work, when i put an if statement before JOptionPane, it never execute even though the condition on the if statement became true because the user clicked the submit button;

else {
						// GUI components

						LayOut gui = new LayOut();
						gui.setSize(648, 590);
							Object obj1 = "Continue or Exit? \n\n";
							Object stringArray1[] = { "Continue", "Exit" };
							if (JOptionPane.showOptionDialog(null, obj1,
									"Continue or Exit",
									JOptionPane.QUESTION_MESSAGE, null,
									stringArray1, obj1) == JOptionPane.YES_OPTION) {




here is the actionlistener for the submit button in my JFrame

private class SubmHandler implements ActionListener {

		public void actionPerformed(ActionEvent arg0) {

				JOptionPane.showMessageDialog(null, "You Have Selected More than 5 Senators, Please Choose Only 5");
				JOptionPane.showMessageDialog(null, "Thank you For Voting");

Recommended Answers

All 2 Replies

Your attachment is not working.Check it.....

If you want the option pane to display when the user clicks the button you need to put that code in the button's action listener and not in your main GUI initialisation code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.