init
This commit is contained in:
70
Reversi/ReversiPlayBoard.java
Normal file
70
Reversi/ReversiPlayBoard.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package reversi.view;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.MouseAdapter;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.CompoundBorder;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.border.MatteBorder;
|
||||
|
||||
import reversi.model.Board;
|
||||
import reversi.model.Field;
|
||||
import reversi.model.Reversi;
|
||||
|
||||
/**
|
||||
* Create a reversi playboard for the reversi game gui.
|
||||
*/
|
||||
public class ReversiPlayBoard extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 2725183063551812386L;
|
||||
private ReversiField[][] playField = new ReversiField
|
||||
[Board.SIZE][Board.SIZE];
|
||||
|
||||
/**
|
||||
* Init array with all reversi fields. Set background and tooltip of
|
||||
* fields.
|
||||
*/
|
||||
public ReversiPlayBoard() {
|
||||
this.setLayout(new GridLayout(Board.SIZE, Board.SIZE));
|
||||
this.setBorder(new CompoundBorder(
|
||||
null, new EmptyBorder(0, 0, 10, 10)));
|
||||
|
||||
for (int row = 0; row < Board.SIZE; row++) {
|
||||
for (int col = 0; col < Board.SIZE; col++) {
|
||||
playField[row][col] = new ReversiField(new Field(row, col));
|
||||
playField[row][col].setBorder(
|
||||
new MatteBorder(1, 1, 0, 0, Color.BLACK));
|
||||
playField[row][col].setBackground(new Color(0, 170, 0));
|
||||
playField[row][col].setToolTipText("Click to make a move!");
|
||||
this.add(playField[row][col]);
|
||||
}
|
||||
}
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update hole playboard players.
|
||||
*
|
||||
* @param board Board to update.
|
||||
*/
|
||||
public void updatePlayBoard(Reversi board) {
|
||||
for (int row = 0; row < Board.SIZE; row++) {
|
||||
for (int col = 0; col < Board.SIZE; col++) {
|
||||
this.playField[row][col].setPlayer(board.getSlot(row, col));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set mouselistener of <code>field</code>
|
||||
*
|
||||
* @param ma Mouseadapter
|
||||
* @param field Field
|
||||
*/
|
||||
public final void setFieldListener(
|
||||
final MouseAdapter ma, final Field field) {
|
||||
this.playField[field.row()][field.col()].setListener(ma);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user