diff --git a/src/de/itsblue/ConnectFour/ButtonRow.java b/src/de/itsblue/ConnectFour/ButtonRow.java new file mode 100644 index 0000000..0305617 --- /dev/null +++ b/src/de/itsblue/ConnectFour/ButtonRow.java @@ -0,0 +1,46 @@ +package de.itsblue.ConnectFour; + +import javax.swing.JButton; + +import javax.swing.*; +import java.awt.*; + +public class ButtonRow extends JPanel{ + + JButton inputButtons[]; + int buttoncount = 0; + + public void InitButton() { + + + // configure the layout + this.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0)); + + for (int i = 0; i < this.buttoncount; i++) { + this.inputButtons[i] = new JButton(); + this.inputButtons[i].setText(""+i); + this.add(this.inputButtons[i]); + } + + } + + ButtonRow(int buttoncount) { + this.buttoncount = buttoncount; + this.inputButtons = new JButton[buttoncount]; + this.InitButton(); + System.out.println("test"); + } + + @Override + public void paint(Graphics g){ + for (int i = 0; i < this.buttoncount; i++) { + + this.inputButtons[i].setPreferredSize(new Dimension(this.getWidth()/this.buttoncount, this.getHeight())); + } + + super.paint(g); + } + + + +} diff --git a/src/de/itsblue/ConnectFour/ConnectFour.java b/src/de/itsblue/ConnectFour/ConnectFour.java index e580b7e..891247e 100644 --- a/src/de/itsblue/ConnectFour/ConnectFour.java +++ b/src/de/itsblue/ConnectFour/ConnectFour.java @@ -40,11 +40,21 @@ public class ConnectFour extends JFrame { this.setPreferredSize(new Dimension(600, 600)); this.getContentPane().setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + + c.gridy = 0; // Board initilisieren + ButtonRow buttonRow = new ButtonRow(7); + buttonRow.setPreferredSize(new Dimension(400,20)); + add(buttonRow,c); + GameBoard board = new GameBoard(); + board.setPreferredSize(new Dimension(400, 400)); - this.add(board); + c.gridy = 1; + this.add(board, c); + // plate in das Board einfügen board.insertPlate(new Plate(PlateType.O), 1); diff --git a/src/de/itsblue/ConnectFour/GameBoard.java b/src/de/itsblue/ConnectFour/GameBoard.java index c8c9626..330f43b 100644 --- a/src/de/itsblue/ConnectFour/GameBoard.java +++ b/src/de/itsblue/ConnectFour/GameBoard.java @@ -23,6 +23,7 @@ import java.awt.*; import de.itsblue.ConnectFour.Plate.PlateType; + /** * GameBoard is a fully usable connect4 game board. It can take plates and * insert them into a given column and check if somebody won the game. @@ -63,8 +64,10 @@ public class GameBoard extends JPanel { */ GameBoard() { this.initBoard(); + } + /** * Function to insert a plate into a specific column * @@ -116,6 +119,8 @@ public class GameBoard extends JPanel { * Function to fill the board with containers */ private void initBoard() { + + // configure the main layout this.setLayout(new GridLayout(this.BoardRows, this.BoardColumns)); @@ -129,8 +134,12 @@ public class GameBoard extends JPanel { this.add(this.BoardContainers[j][i]); } } + } + + + /** * Function to calculate a size for the containers to fit a given dimension *