added Buttons
This commit is contained in:
parent
f4098bf044
commit
b3a02801db
3 changed files with 66 additions and 1 deletions
46
src/de/itsblue/ConnectFour/ButtonRow.java
Normal file
46
src/de/itsblue/ConnectFour/ButtonRow.java
Normal file
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
Reference in a new issue