954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

cancelling the actionPerformed

Hello all,
is there a way to cancel or abort the execution of current actionPerformed? My problem is that, when the control is passed to the listener method, i perform checking if certain value is null, if so, display Error Msg using JOP. when user click OK, then the actionPerformed method should stop from executing the rest of the statements.. i use the System.exit(1).. but it terminated the app. Below is the code:

public void actionPerformed(ActionEvent nextbtn)
			{
				Object source =  nextbtn.getSource();
				if(source==btnNext)
				{


									String stuAnswer = txtAnswer.getText();
									if(stuAnswer.equals(" "))
									{
										JOptionPane.showMessageDialog(this, "You have to input an Answer!",
																	"Empty Answer Detected..",
																	JOptionPane.ERROR_MESSAGE);
										System.exit(1);
									}
									else
									{

									String questions = questionInput.nextLine();

									lblQuestion.setText(questions);

									studentAnswer[count] =  txtAnswer.getText();
									count++;
									txtAnswer.setText("");

									if(count>=9)
									{
										btnNext.setEnabled(false);
										btnScore.setEnabled(true);
									}
								}

				}
Caled
Newbie Poster
22 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

You really don't need to cancel execution of the method, just don't perform any other actions after the display of the message. It looks like your current method will do that just fine as it is. Just remove the System.exit() call.

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

Actually things could be much simpler... duno why i always come up w/ complicated ways..I removed the system.exit(1).. and after user press OK of the JOP, the control is passed back to the current frame w/o advancing to the next frame... forgive me for my complete ignorance... need to read more...

Caled
Newbie Poster
22 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

Thanks Ezzarral...just figured it out... Thankies :-)

Caled
Newbie Poster
22 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You