-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewer.java
52 lines (44 loc) · 1.2 KB
/
Viewer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
/**
* Represents a view that displays the chess board.
*/
public class Viewer extends JFrame {
/** Represents a chess game i.e., the model. */
private final Game game;
/** Represents an event handler i.e., the controller. */
private final Controller controller;
/**
* Initializes the viewer.
*
* @param game is a chess game
* @param controller is an event handler
*/
public Viewer(Game game, Controller controller) {
this.game = game;
this.controller = controller;
display();
}
/**
* Displays the Swing displayer.
*/
private void display() {
setTitle("Chess by Dobe");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
// Create the BoardPanel and add to frame
Board board = game.getBoard();
MultiBoardPanel boardPanel = new MultiBoardPanel(board, controller, board.getLevel());
//boardPanel.init();
add(boardPanel, BorderLayout.CENTER);
// Full-screen frame
setPreferredSize(new Dimension(600, 600));
setResizable(true);
// Set up other UI
pack();
setVisible(true);
// Add an observer for the board
game.addObserver(boardPanel);
}
}