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
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).]
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).
Joined: May 09, 2001
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
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.
"JavaRanch, where the deer and the Certified play" - David O'Meara