2018-04-16 13:40:41 +02:00

62 lines
1.7 KiB
Java

package interfaces;
import board.IBoard;
import objects.GameObject;
import objects.Player;
import objects.Token;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
public abstract class GUI implements ActionListener, IGameInterface {
final int BUTTON_HEIGHT = 25;
final int BUTTON_WIDTH = 50;
final int TILE_HEIGHT = 50;
final int HEIGHT_GAP = 10;
final int WIDTH_GAP = 10;
JButton[] dropButtons;
JButton resetButton;
JTextPane[] tiles;
JLabel infoLabel;
IBoard board;
JPanel mainPanel;
JFrame frame;
Player currentPlayer;
public void displayBoard() {
for (JTextPane pane : this.tiles) {
this.mainPanel.remove(pane);
}
this.tiles = new JTextPane[this.board.getWidth() * this.board.getHeight()];
readTiles();
this.frame.validate();
}
void readTiles() {
int k = 0;
for (int i = board.getHeight() - 1; i > -1; i--) {
for (int j = 0; j < board.getWidth(); j++) {
JTextPane textPane = new JTextPane();
this.tiles[k++] = textPane;
textPane.setEditable(false);
textPane.setBackground(Color.BLUE);
GameObject obj = board.get(j,i);
textPane.setBorder(BorderFactory.createLineBorder(obj.getColor(), 50, true));
textPane.setPreferredSize(new Dimension(BUTTON_WIDTH, TILE_HEIGHT));
mainPanel.add(textPane, BorderLayout.PAGE_START);
}
}
}
boolean dropObject(int i) {
return this.board.drop(i, new Token(currentPlayer));
}
public void displayMessage(String s) {
infoLabel.setText(s);
}
}