created a simple plate
This commit is contained in:
parent
483b214d9b
commit
672ba733e5
2 changed files with 31 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
||||||
package de.itsblue.ConnectFour;
|
package de.itsblue.ConnectFour;
|
||||||
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
import java.awt.GridBagLayout;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
|
||||||
public class ConnectFour extends JFrame {
|
public class ConnectFour extends JFrame {
|
||||||
|
@ -17,12 +17,17 @@ public class ConnectFour extends JFrame {
|
||||||
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
this.setPreferredSize(new Dimension(600,600));
|
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
|
// finish up
|
||||||
this.pack();
|
this.pack();
|
||||||
this.setVisible(true);
|
this.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(final String[] args) {
|
||||||
System.out.println(new ConnectFour());
|
System.out.println(new ConnectFour());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,6 +2,9 @@ package de.itsblue.ConnectFour;
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
|
||||||
public class Plate extends JPanel {
|
public class Plate extends JPanel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,8 +12,27 @@ public class Plate extends JPanel {
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 1L;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Reference in a new issue