JavaSa
JavaSa

Reputation: 6241

How to extract the button which was pressed from JDialog?

I've generated a JDialog with the use of JOption C'tor in the following lines:

 Object[] options =
            {
        "Yes", "No (Exit to main menu)"
        };
        JOptionPane messagePane = new JOptionPane(i_StringMessage+"\nDo you want to begin another Net Game?", JOptionPane.INFORMATION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options);
        messagePane.setLocation(500, 1000);
        JDialog dialog = messagePane.createDialog(m_GameApplet.GetJpanelStartNetGame(), "Game over");
        m_GameApplet.GetJpanelStartNetGame().SetPopUpWindowReference(dialog);
        m_GameApplet.GetJpanelStartNetGame().GetPopUpWindowReference().setVisible(true);

I set the JDialog to be visible, but I wonder how can I now receive and parse the button that the user has clicked on, in a similar way to using the static JOption functions like that:

int userChoice = JOptionPane.showOptionDialog(this, i_StringMessage+"\nDo you want to begin another Net Game?",
                "Game over", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);

How can I close a JDialog, and what does dispose function excately do?
Thanks

Upvotes: 1

Views: 1740

Answers (1)

James Jithin
James Jithin

Reputation: 10565

See the "Direct Use:" section in the link below:

http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/JOptionPane.html

You will need to get the selected value using getValue() of JOptionPane and parse accordingly.

Upvotes: 1

Related Questions