From 672ba733e56046d7b5814eeec0faf697a5f05588 Mon Sep 17 00:00:00 2001 From: dorian Date: Wed, 5 Feb 2020 15:29:52 +0100 Subject: [PATCH] created a simple plate --- src/de/itsblue/ConnectFour/ConnectFour.java | 9 +++++-- src/de/itsblue/ConnectFour/Plate.java | 26 +++++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/de/itsblue/ConnectFour/ConnectFour.java b/src/de/itsblue/ConnectFour/ConnectFour.java index 0a1f57f..7680f2d 100644 --- a/src/de/itsblue/ConnectFour/ConnectFour.java +++ b/src/de/itsblue/ConnectFour/ConnectFour.java @@ -1,7 +1,7 @@ package de.itsblue.ConnectFour; import java.awt.Dimension; - +import java.awt.GridBagLayout; import javax.swing.JFrame; public class ConnectFour extends JFrame { @@ -17,12 +17,17 @@ public class ConnectFour extends JFrame { this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setPreferredSize(new Dimension(600,600)); + this.setLayout(new GridBagLayout()); + this.add(new Plate(Plate.PlateType.X)); + + this.add(new Plate(Plate.PlateType.O)); + // finish up this.pack(); this.setVisible(true); } - public static void main(String[] args) { + public static void main(final String[] args) { System.out.println(new ConnectFour()); } } \ No newline at end of file diff --git a/src/de/itsblue/ConnectFour/Plate.java b/src/de/itsblue/ConnectFour/Plate.java index be98c86..15b5027 100644 --- a/src/de/itsblue/ConnectFour/Plate.java +++ b/src/de/itsblue/ConnectFour/Plate.java @@ -2,6 +2,9 @@ package de.itsblue.ConnectFour; import javax.swing.JPanel; +import java.awt.Color; +import java.awt.Dimension; + public class Plate extends JPanel { /** @@ -9,8 +12,27 @@ public class Plate extends JPanel { */ private static final long serialVersionUID = 1L; - Plate() { - + enum PlateType { + X, O + } + + private PlateType type; + + Plate(PlateType type) { + this.setType(type); + + this.setPreferredSize(new Dimension(10, 10)); + + this.setBackground(this.type == PlateType.X ? Color.RED:Color.BLACK); + + } + + public PlateType getType() { + return type; + } + + private void setType(PlateType type) { + this.type = type; } } \ No newline at end of file