From 001ecfc3c8a2ee594999d059b5053913f0985768 Mon Sep 17 00:00:00 2001 From: Yazan Alaamer Date: Fri, 20 Jan 2023 22:08:05 +0100 Subject: [PATCH] add ChoiceHandler & set action command choices --- src/main/java/game/StartDarkSoulsGame.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/game/StartDarkSoulsGame.java b/src/main/java/game/StartDarkSoulsGame.java index 0d73f5f..c744385 100644 --- a/src/main/java/game/StartDarkSoulsGame.java +++ b/src/main/java/game/StartDarkSoulsGame.java @@ -30,6 +30,7 @@ public class StartDarkSoulsGame { JButton StartButton, choice1, choice2, choice3, choice4; Container con; TitelScreenHandler tsHandler= new TitelScreenHandler(); + ChoiceHandler choiceHandler = new ChoiceHandler(); int playerHP ; String position; String weapon; @@ -94,6 +95,7 @@ public class StartDarkSoulsGame { choice1.setForeground(Color.white); choice1.setFont(normalFont); choice1.setFocusPainted(false); + choice1.setActionCommand("c1"); choiceButtonPanel.add(choice1); choice2 = new JButton("Choice 2"); @@ -101,6 +103,7 @@ public class StartDarkSoulsGame { choice2.setForeground(Color.white); choice2.setFont(normalFont); choice2.setFocusPainted(false); + choice2.setActionCommand("c2"); choiceButtonPanel.add(choice2); choice3 = new JButton("Choice 3"); @@ -108,6 +111,7 @@ public class StartDarkSoulsGame { choice3.setForeground(Color.white); choice3.setFont(normalFont); choice3.setFocusPainted(false); + choice3.setActionCommand("c3"); choiceButtonPanel.add(choice3); choice4 = new JButton("Choice 4"); @@ -115,6 +119,7 @@ public class StartDarkSoulsGame { choice4.setForeground(Color.white); choice4.setFont(normalFont); choice4.setFocusPainted(false); + choice4.setActionCommand("c4"); choiceButtonPanel.add(choice4); playerPanel = new JPanel(); @@ -168,6 +173,11 @@ public class StartDarkSoulsGame { choice3.setText(""); choice4.setText(""); } + public class ChoiceHandler implements ActionListener{ + public void actionPerformed(ActionEvent event) { + String yourChoice = event.getActionCommand(); + } + } public class TitelScreenHandler implements ActionListener{ public void actionPerformed(ActionEvent event) { createGameScreen();