• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JOptionPane.showOptionDialog

 
Ranch Hand
Posts: 36
Eclipse IDE Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are you having trouble understanding? The syntax?
 
Jacob Coddaire
Ranch Hand
Posts: 36
Eclipse IDE Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 36
Eclipse IDE Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't figure out how to make it show a list of names, or anything , for that matter.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should be using a showInputDialog instead :


(there are some examples in the java tutorial)
 
Jacob Coddaire
Ranch Hand
Posts: 36
Eclipse IDE Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 36
Eclipse IDE Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok I got it to work. Sweet and thanks.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic