How to catch the Event of JoptionPane

Hi experts,

following is a small snippet of my code

<snip>
try{
   CheckValueException.checkValues(lows_Datapass,
prtxt_Oldpass.getText());
  }
  catch(CheckValueException cve){
   int x = JOptionPane.showConfirmDialog(prfra_Main, "Password doesnt
match try again", "Error", JOptionPane.DEFAULT_OPTION);
   System.out.println("The int is " + x);
   prtxt_Oldpass.requestFocus();
  }
</snip>

After this joption message i want the entire program to terminate, but
after clicking the okay button it is moving to the next block.

How shall i implement that??  Please help me.

Thanks
Srini

seenuvAsked:
Who is Participating?
 
jsridharConnect With a Mentor Commented:
>>After this joption message i want the entire program to terminate, but
after clicking the okay button it is moving to the next block.

Since you wanted the "entire program to terminate" i suggested to add:

System.exit(0);

The general way of doing "wrong password" message boxes are:

1. show the error message dialog using:
JOptionPane.showMessageDialog
2. set the focus to the field and return from the function.

The code has to be written in the event handler code of the button.

Still it is not very clear as what you want!!!

js.
0
 
jsridharCommented:
add the line:

System.exit(0);

at the place where you would wish the application to terminate.

js.
0
 
seenuvAuthor Commented:
no what i need is that i need the focus again to a textfiled system.exit(0) will make the window disappear and will terminate the whole application, but i need the application but the execution alone should terminate, say when i click theokay button i need the focus again to the textfield and the code should not move further.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
jsridharCommented:
>>After this joption message i want the entire program to terminate, but
after clicking the okay button it is moving to the next block.

Since you wanted the "entire program to terminate" i suggested to add:

System.exit(0);

The general way of doing "wrong password" message boxes are:

1. show the error message dialog using:
JOptionPane.showMessageDialog
2. set the focus to the field and return from the function.

The code has to be written in the event handler code of the button.

Still it is not very clear as what you want!!!

js.
0
 
seenuvAuthor Commented:
no what i need is that i need the focus again to a textfiled system.exit(0) will make the window disappear and will terminate the whole application, but i need the application but the execution alone should terminate, say when i click theokay button i need the focus again to the textfield and the code should not move further.
0
 
seenuvAuthor Commented:
sorry for posting that comment again it was not intentionally done, yes i now got some logic, u mean to say return true or false as per the output right??.

I shall take care sridhar thanks for ur assistance,  u propose this as an answer i shall accept it.

Thanks
Srini

ps EXPERTS PLEASE PROPOSE ANY ANSWER AS I SRIDHAR DESERVES POINTS.
0
All Courses

From novice to tech pro — start learning today.