mardi 1 décembre 2015

register a button click in an if statement

Here is my code:

else if (roomNumber == 3) {
            txtAreaDisplay.append("Oh no, it looks like you have run into a monster!\n"
                    + "The monster runs straight at you, looking for a fight.\n"
                    + "Are you going to fight, or run?\n");

            //fight
            if (btnFight.getModel().isPressed()) {
                txtAreaDisplay.append("You have chosen to fight the monster!\n");
            }

            //run
            else if (btnRun.getModel().isPressed()) {
                txtAreaDisplay.append("You have chosen to attempt to run away from the monster!\n");
            }
        }

My question is, how do I go about registering the button click in the if statement (if that makes sense)? I have the line: (btnFight.getModel().isPressed()) but that does not seem to work because when I press the button, the next line is not outputted.

Any help is greatly appreciated!

Aucun commentaire:

Enregistrer un commentaire