This repository has been archived on 2022-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
connect-four/src/de/itsblue/ConnectFour/ControllRow.java

94 lines
2.6 KiB
Java

/*
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);
}
}