From 12a1010b63e20ef56f73041cbc57e69a71e26408 Mon Sep 17 00:00:00 2001 From: Steffen Helmke Date: Mon, 10 Jan 2022 14:24:10 +0100 Subject: [PATCH] 4gewinnt: refactored and externalized gui-testing --- .../java/de/tims/viergewinnt/ai/GuiTest.java | 21 +++++++++++ .../java/de/tims/viergewinnt/ai/Logic.java | 35 ++++--------------- 2 files changed, 28 insertions(+), 28 deletions(-) create mode 100644 src/main/java/de/tims/viergewinnt/ai/GuiTest.java diff --git a/src/main/java/de/tims/viergewinnt/ai/GuiTest.java b/src/main/java/de/tims/viergewinnt/ai/GuiTest.java new file mode 100644 index 0000000..be0aa60 --- /dev/null +++ b/src/main/java/de/tims/viergewinnt/ai/GuiTest.java @@ -0,0 +1,21 @@ +package de.tims.viergewinnt.ai; + +import javax.swing.JFrame; + +public class GuiTest { + + JFrame frame; + public GuiTest() { + frame = new JFrame(); + frame.setSize(500, 500); + Logic logic = new Logic(); + frame.add(logic.create4gewinntGui()); + frame.setVisible(true); + } + + public static void main(String[] args) { + // TODO Auto-generated method stub + GuiTest testGui = new GuiTest(); + } + +} diff --git a/src/main/java/de/tims/viergewinnt/ai/Logic.java b/src/main/java/de/tims/viergewinnt/ai/Logic.java index 356a777..4096ce6 100644 --- a/src/main/java/de/tims/viergewinnt/ai/Logic.java +++ b/src/main/java/de/tims/viergewinnt/ai/Logic.java @@ -1,40 +1,25 @@ package de.tims.viergewinnt.ai; import java.awt.Color; -import java.awt.Dimension; import java.awt.GridLayout; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JButton; -import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class Logic { - //"static" only for testing, remove when finished - //only for testing, remove when finished - static JFrame content; + JPanel contentPanel; + JPanel buttonPanel; + JPanel playfieldPanel; + JButton[] buttons = new JButton[6]; + JLabel[] gamefield = new JLabel[36]; - static JPanel contentPanel; - static JPanel buttonPanel; - static JPanel playfieldPanel; - static JButton[] buttons = new JButton[6]; - static JLabel[] gamefield = new JLabel[36]; - - public static JPanel create4gewinntGui() { - - //only for testing, remove when finished - content = new JFrame(); - content.setSize(500,500); - + public JPanel create4gewinntGui() { contentPanel = new JPanel(); - contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.PAGE_AXIS)); - - //only for testing, remove when finished - content.add(contentPanel); - + contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.PAGE_AXIS)); buttonPanel = new JPanel(new GridLayout(1, 6)); playfieldPanel = new JPanel(new GridLayout(6, 6)); contentPanel.add(buttonPanel); @@ -54,12 +39,6 @@ public class Logic { return contentPanel; } - //only for testing, remove when finished - public static void main(String[] args) { - create4gewinntGui(); - content.setVisible(true); - } - public boolean testForWin(int[][] playfield, int player) { int chain = 0; for(int i = 0; i < playfield[0].length; i++) {