Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting response from a dialog box

 
Mick Flynn
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I created a dialog box class called YNDialog by subclassing JDialog. It has two buttons, (predictably enough) labelled Yes and No.
Question: how do I get the YNDialog object to tell the rest of my application which button was clicked?
Thanks
MF
 
Wirianto Djunaidi
Ranch Hand
Posts: 210
Ruby Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike,
Depend on what you want to do. If you just need a standard Yes and No dialog, you can us the JOptionPane.
But if you really want to implement your own, then your dialog should handle the Events for the button and probably wrap them up and provide a method like addXXXListener() for your main application. And have your application implement the Listener interface.
Good luck,
-Ryo
[This message has been edited by Ryo Saeba (edited June 18, 2001).]
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your subclassed YNDialog, you can have either a single boolean, or one for each answer (makes checking with if's in the client application a bit easier)... and in the actionEvent for the Yes button, you'd set YNDialog.YES = true, and YNDialog.NO = false, or a single variable YNDialog.ANSWER = true

then once the dialog has disappeared your client application would examine the variables and determine which button had been clicked. If encapsulation appeals to you, you can make it private variables and a method, probably

boolean YNDialog.getAnswer() //(true for Yes, false for No).
 
Mick Flynn
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike, Ryo,
Thanks a million for that - in fact JOptionPane was what I've been looking for for weeks... I thought the only option was to subclass JDialog.
Muchas gracias!
MF
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mick,
Don't you find that getting to KNOW all the stuff that is out there in the API, and understanding where it would be useful, it a major part of the battle. I know I run into things ALL THE TIME that I wish I had known for something or other earlier.
Ah Well, I just keep plowing on.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic