how do i use jframe button to send input selection
i am trying to send selection from jframe button and get the selection for the program. What am i doing wrong?
Public class Main {
private static enum Command {
F, // fight
R, // rest
B, // buy weapon
C, // status
Q, // quit
UNDEFINED;
}
public static void main(String... args) throws IOException {
// create the opponents
final Opponent goodman = new Opponent("Goodman", 50, false);
final Opponent monster = new Opponent("Monster", 50, true);
// initiate the fight
final Fight fight = new Fight(goodman, monster);
// input switch statement
// loop while both are alive
while (fight.isOngoing()) {
JFrame frame = new JFrame("Goodman Vs. Monster - Round 1");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setLayout(new GridLayout(1,5));
frame.add(new JButton("Go out and fight"));
frame.add(new JButton("Buy Weapon"));
frame.add(new JButton("R: Rest"));
frame.add(new JButton("C: Check Stats"));
frame.add(new JButton("Q: Quit"));
frame.pack();
frame.setVisible(true);
switch (readCommand()) {
case F:
System.out.println("f: Continue the fight");
fight.fight();
if (!fight.isOngoing()) {
fight.end();
}
break;
case R:
fight.rest();
break;
case C:
System.out.println("c: Fight-Status:");
fight.getStats();
break;
case B:
System.out.println("b: Buy Weapon:");
System.out.println(Weapon.getBuyableWeapons());
Weapon weapon = readWeapon();
fight.buy(goodman, weapon);
break;
case Q:
System.out.println("q: You quit: Game over");
System.exit(0);
break;
default:
System.out.println("--> Invalid selection");
break;
}