craig smith
craig smith

Reputation: 23

Trouble with JOptionPane and getting it to work

trying to create a joptionpane to work any ideas why this isnt working?

public void playerLost() {

    if(player.getStaminaLevel() < player.getStaminaNeededToMove(Terrain.SAND)) {

                JOptionPane.YES_NO_OPTION(

        if (JOptionPane.NO_OPTION) {
            dispose();
        }
        else
        {
            game = new Game();
            createGridSquarePanels();
            update();
        }
}

i also tried this but says JOptionPane.NO_OPTION cannot be converted from int to string

    public void playerLost() {

    if(player.getStaminaLevel() < player.getStaminaNeededToMove(Terrain.SAND)) {
        int choice = JOptionPane.showConfirmDialog(
        this, 
                "sorry you lost\nWould you like to restart?",
                JOptionPane.YES_NO_OPTION,
                JOptionPane.INFORMATION_MESSAGE);
        if (choice == JOptionPane.NO_OPTION) {
            dispose();
        }
        else
        {
            game = new Game();
            createGridSquarePanels();
            update();
        }
}
}

Upvotes: 0

Views: 66

Answers (1)

Reimeus
Reimeus

Reputation: 159754

The first snippet doesn't compile as the syntax is invalid for using a JOptionPane.

In the second piece of code, you're missing the title argument

int choice = JOptionPane.showConfirmDialog(this, 
                "sorry you lost\nWould you like to restart?",
                "Title",
                JOptionPane.YES_NO_OPTION,
                JOptionPane.INFORMATION_MESSAGE);

Consult the JOptionPane javadoc

Upvotes: 1

Related Questions