aspose file tools*
The moose likes Beginning Java and the fly likes JOptionPane.showOptionDialog Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JOptionPane.showOptionDialog" Watch "JOptionPane.showOptionDialog" New topic
Author

JOptionPane.showOptionDialog

Jacob Coddaire
Ranch Hand

Joined: Jan 11, 2011
Posts: 36

Hey guys. I'm having trouble understanding the concept of this command. I'm creating a small game. Here's what I need to do.
1) Have a user specify how many players (2-4)
2) Have the user create names, or custom strings, for each player
3) Sort the names in an array
4) Create a dialog box that throws up the names and allows the user to select which will go first. The selection process should be either a JButton or radio button style, and should include the custom name set by the user.

For the record, steps one through three are done. My instructor said that this method would be the best for displaying the information I needed.

Here is what I figure:
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1726
    
  12

What are you having trouble understanding? The syntax?


When you do things right, people won't be sure you've done anything at all.
Jacob Coddaire
Ranch Hand

Joined: Jan 11, 2011
Posts: 36

For some reason, it keeps getting this error message.
Exception in thread "main" java.lang.NullPointerException
at javax.swing.plaf.basic.BasicOptionPaneUI.addButtonComponents(Unknown Source)
at javax.swing.plaf.basic.BasicOptionPaneUI.createButtonArea(Unknown Source)
at javax.swing.plaf.basic.BasicOptionPaneUI.installComponents(Unknown Source)
at javax.swing.plaf.basic.BasicOptionPaneUI.installUI(Unknown Source)
at javax.swing.JComponent.setUI(Unknown Source)
at javax.swing.JOptionPane.setUI(Unknown Source)
at javax.swing.JOptionPane.updateUI(Unknown Source)
at javax.swing.JOptionPane.<init>(Unknown Source)
at javax.swing.JOptionPane.showOptionDialog(Unknown Source)
at Input.main(Input.java:60)

Here's my full code.

Jacob Coddaire
Ranch Hand

Joined: Jan 11, 2011
Posts: 36

I can't figure out how to make it show a list of names, or anything , for that matter.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

You should be using a showInputDialog instead :


(there are some examples in the java tutorial)


[My Blog]
All roads lead to JavaRanch
Jacob Coddaire
Ranch Hand

Joined: Jan 11, 2011
Posts: 36

This works, but it has a small defect. I can select a blank space when there is nothing there. Is there a way to work around this?
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1726
    
  12

Jacob,

Did you see the tutorial? If so,



Your best bet would be to initialize the array once you find out how many players there will be. Then you can just use that array in the input dialog. Otherwise, you'll need to create another array once you figure out there's only 2 players or whatever.
Jacob Coddaire
Ranch Hand

Joined: Jan 11, 2011
Posts: 36

Ok I got it to work. Sweet and thanks.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JOptionPane.showOptionDialog