Replaced having 1 MouseListener per Tile JLabel which a single listener which asks the event's associated component for its row, column.
This isn't ideal, but is preferable to putting this information in each of rows x columns different mouse listeners. Also added a title to the MainFrame.
This commit is contained in:
@@ -35,14 +35,14 @@ public class BoardPanel extends JPanel {
|
||||
referee = ref;
|
||||
setLayout(new GridLayout(Board.NUM_ROWS, Board.NUM_COLS));
|
||||
|
||||
BoardPanelMouseListener bpml = new BoardPanelMouseListener(this, tsp, referee.getPlayer());
|
||||
ImageIcon noneIcon = new ImageIcon(NONE_ICON);
|
||||
for (int r = 0; r < Board.NUM_ROWS; r++) {
|
||||
for (int c = 0; c < Board.NUM_COLS; c++) {
|
||||
board[r][c] = new JLabel(new ImageIcon(NONE_ICON));
|
||||
BoardPanelMouseListener bpml = new BoardPanelMouseListener(this, tsp, r,
|
||||
c, referee.getPlayer());
|
||||
|
||||
// separate listener on each JLabel? This should probably be
|
||||
// changed.
|
||||
Tile tile = new Tile(noneIcon,r,c);
|
||||
board[r][c] = tile;
|
||||
tile.addMouseListener(bpml);
|
||||
|
||||
board[r][c].addMouseListener(bpml);
|
||||
board[r][c].addMouseWheelListener(bpml);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user