views:

3352

answers:

1

Hey all,

I was wondering if there is a JOptionPane where you can get multiple inputs from a user instead of just one? If not, how could i accomplish this using some type of prompt. I am creating Battleship, and wanted to prompt the user to specify locations to place each ship.

Thanks,

Tomek

+5  A: 

The object that you pass in as the message to the JOptionPane can be graphical components, so something like this should work:

JPanel panel = new JPanel();
// Populate your panel components here.
int ret = JOptionPane.showConfirmDialog(parent, panel, "Title", JOptionPane.YES_NO_OPTION);
if ( ret == JOptionPane.YES_OPTION )
{
  // Read component values.
}
Evan