added new controllbuttons, still no functionality

This commit is contained in:
oliver 2020-02-25 10:44:24 +01:00
parent b36b0f549f
commit 8ae82e9f9a
2 changed files with 127 additions and 23 deletions

View file

@ -37,6 +37,8 @@ public class ConnectFour extends JFrame implements PlayerMoveListener {
private ButtonRow buttonRow;
private ControllRow controllRow;
private int player = 0;
private Player players[] = new Player[2];
@ -44,9 +46,7 @@ public class ConnectFour extends JFrame implements PlayerMoveListener {
private GameType gameType;
enum GameType {
Local,
RemoteServer,
RemoteClient
Local, RemoteServer, RemoteClient
}
/**
@ -69,10 +69,19 @@ public class ConnectFour extends JFrame implements PlayerMoveListener {
// initialize ButtonRow
this.buttonRow = new ButtonRow(this.gameBoard.getColumns());
// initialize ContollRow
this.controllRow = new ControllRow(this.gameBoard.getColumns());
// add components to window
c.gridx = 0;
c.gridy = 0;
add(buttonRow, c);
c.gridx = 13;
c.gridy = 1;
add(controllRow, c);
c.gridx = 0;
c.gridy = 1;
this.add(gameBoard, c);
@ -129,8 +138,7 @@ public class ConnectFour extends JFrame implements PlayerMoveListener {
if (player == 0) {
player = 1;
}
else{
} else {
player = 0;
}
@ -186,6 +194,9 @@ public class ConnectFour extends JFrame implements PlayerMoveListener {
// set button row size
this.buttonRow.setPreferredSize(
new Dimension(this.gameBoard.getPreferredSize().width, this.gameBoard.getPreferredSize().height / 7));
// set button column size
this.controllRow.setPreferredSize(
new Dimension(this.gameBoard.getPreferredSize().width / 4, this.gameBoard.getPreferredSize().height));
// call super
super.validate();

View file

@ -0,0 +1,93 @@
/*
Connect four - written in java
Copyright (C) 2020 Oliver Schappacher and Dorian Zedler
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.itsblue.ConnectFour;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* Button row is a class meant for usage with de.itsblue.ConnectFour.
*
* @author Oliver Schappacher
* @author Dorian Zedler
*/
public class ControllRow extends JPanel {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Array that sores all buttons in the column
*/
private JButton inputButtons[];
/**
* The number of buttons in the row
*/
private int buttonCount = 0;
/**
* Constructor
*
* @param buttonCount The number of buttons to create
*/
ControllRow(int buttonCount) {
// configure basic values
this.buttonCount = 3;
this.inputButtons = new PlateInsertButton[buttonCount];
String[] Titel = {"exit", "new Game", "current Player"};
// configure the layout
this.setLayout(new GridLayout(7, 1));
// insert all the buttons
for (int i = 0; i < this.buttonCount; i++) {
this.inputButtons[i] = new PlateInsertButton(i);
this.inputButtons[i].setText(Titel[i]);
this.add(this.inputButtons[i]);
}
}
/**
* Function to add an ActionListener to all contained buttons
*
* @param listener
*/
public void addActionListenerToButtons(ActionListener listener) {
for (int i = 0; i < this.buttonCount; i++) {
this.inputButtons[i].addActionListener(listener);
}
}
/**
* Override the paint function in order to adjust the button size when rescaling
*/
@Override
public void paint(Graphics g) {
Dimension size = this.getSize();
for (int i = 0; i < this.buttonCount; i++) {
this.inputButtons[i].setPreferredSize(new Dimension(size.width / this.buttonCount, size.height));
}
super.paint(g);
}
}