From dc09cc88a9215cfcf67c9e81d6e3305fce44c259 Mon Sep 17 00:00:00 2001 From: Steffen Helmke Date: Mon, 10 Jan 2022 18:45:49 +0100 Subject: [PATCH] 4gewinnt: added actionListener to buttons --- .../java/de/tims/viergewinnt/ai/Logic.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/main/java/de/tims/viergewinnt/ai/Logic.java b/src/main/java/de/tims/viergewinnt/ai/Logic.java index 4096ce6..0f5f61c 100644 --- a/src/main/java/de/tims/viergewinnt/ai/Logic.java +++ b/src/main/java/de/tims/viergewinnt/ai/Logic.java @@ -2,6 +2,8 @@ package de.tims.viergewinnt.ai; import java.awt.Color; import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import javax.swing.BorderFactory; import javax.swing.BoxLayout; @@ -27,6 +29,7 @@ public class Logic { for(int i = 0; i < buttons.length; i++) { buttons[i] = new JButton(Integer.toString(i+1)); + buttons[i].addActionListener(new ButtonListener()); buttonPanel.add(buttons[i]); } @@ -39,6 +42,32 @@ public class Logic { return contentPanel; } + class ButtonListener implements ActionListener { + + @Override + public void actionPerformed(ActionEvent e) { + if(e.getSource() == buttons[0]) { + + } + if(e.getSource() == buttons[1]) { + + } + if(e.getSource() == buttons[2]) { + + } + if(e.getSource() == buttons[3]) { + + } + if(e.getSource() == buttons[4]) { + + } + if(e.getSource() == buttons[5]) { + + } + } + + } + public boolean testForWin(int[][] playfield, int player) { int chain = 0; for(int i = 0; i < playfield[0].length; i++) {