Browse Source

4gewinnt: refactored and externalized gui-testing

4gewinnt
Steffen Helmke 3 years ago
committed by Lorenz Hohmann
parent
commit
12a1010b63
  1. 21
      src/main/java/de/tims/viergewinnt/ai/GuiTest.java
  2. 35
      src/main/java/de/tims/viergewinnt/ai/Logic.java

21
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();
}
}

35
src/main/java/de/tims/viergewinnt/ai/Logic.java

@ -1,40 +1,25 @@
package de.tims.viergewinnt.ai; package de.tims.viergewinnt.ai;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout; import java.awt.GridLayout;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.BoxLayout; import javax.swing.BoxLayout;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
public class Logic { 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 = 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)); buttonPanel = new JPanel(new GridLayout(1, 6));
playfieldPanel = new JPanel(new GridLayout(6, 6)); playfieldPanel = new JPanel(new GridLayout(6, 6));
contentPanel.add(buttonPanel); contentPanel.add(buttonPanel);
@ -54,12 +39,6 @@ public class Logic {
return contentPanel; 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) { public boolean testForWin(int[][] playfield, int player) {
int chain = 0; int chain = 0;
for(int i = 0; i < playfield[0].length; i++) { for(int i = 0; i < playfield[0].length; i++) {

Loading…
Cancel
Save