created a simple plate

This commit is contained in:
Dorian Zedler 2020-02-05 15:29:52 +01:00
parent 483b214d9b
commit 672ba733e5
2 changed files with 31 additions and 4 deletions

View file

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

View file

@ -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;
}
}