Results 1 to 3 of 3
Thread: JOptionPane - editing options
- 03-17-2010, 02:03 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 5
- Rep Power
- 0
JOptionPane - editing options
I have a JOption Pane with customised options text, I was just wondering if there's a way to make the options do something else other than just close the window when it pops up?
This is what i have so far:
I already have defined methods in this class to play again and exit, and i want them to be called when the user selects one of these options on this JOptionPane. But at the moment, whatever button you click, it just closes the window.Java Code:Object[] options = {"Play Again", "Exit"}; JOptionPane.showOptionDialog (frame, "Player X wins", "Congratulations", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
-
If you want the dialog to remain open, you'll need to use a custom JDialog. Otherwise if you want to play again or exit based on the response of the user, simply get the button pressed after the option pane closes.
note 1: code not tested.Java Code:int response = JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); if (response != JOptionPane.CLOSED_OPTION) { if (options[response].equals("Play Again")) { // do your stuff to play again } else { // exit } }
note 2: please do not multipost the same question in multiple fora on this site. Also don't cross-post on other sites without notifying others in your posts. Thanks for your cooperation.
note 3: you may wish to reply to the posts made in your thread from yesterday. Your thanks are how folks are "paid" around here. Again, thanks for your cooperation.
- 03-22-2010, 05:05 PM #3
Member
- Join Date
- Mar 2010
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
VM options + applet
By ProgrammingPup in forum Java AppletsReplies: 1Last Post: 12-24-2009, 05:21 AM -
Menu Options For User
By mnand in forum New To JavaReplies: 1Last Post: 02-02-2009, 03:12 AM -
JOptionPane - showConfirmDialog(...) options
By Java Tip in forum Java TipReplies: 0Last Post: 12-17-2007, 09:38 AM -
ComboBox with database options
By Goldy in forum Advanced JavaReplies: 0Last Post: 12-01-2007, 09:43 PM -
problem with Java Vm options
By DonnieDarko in forum Advanced JavaReplies: 1Last Post: 11-21-2007, 03:22 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks