-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreasureGameView.java
More file actions
140 lines (110 loc) · 3.94 KB
/
TreasureGameView.java
File metadata and controls
140 lines (110 loc) · 3.94 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* Lead Author:
* Ian Kligman; 5550139764
*
* References:
* Gaddis, T. (2015). Starting Out With Java Myprogramming Lab
* From Control Structures Through Objects. (6th ed.). Addison-Wesley.
*
*
* Version: 12/15/2022
*/
/**
* |-----------------------------------------------------------|
* | TreasureGameView |
* |-----------------------------------------------------------|
* | Responsibilities | Collaborating Classes |
* |-------------------------------+---------------------------|
* | Create the game window. | |
* | | GameInfoPanel |
* | | GameFieldPanel |
* | Uses BorderLayout | LastMovePanel |
* | | |
* |-------------------------------+---------------------------|
*/
// Required library imports for GUI and event listeners.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TreasureGameView extends JFrame
{
private JPanel titlePanel;
private JLabel title;
private GameInfoPanel west;
private LastMovePanel south;
private GameFieldPanel center;
private LegendPanel east;
private JMenuBar menuBar;
private JMenu fileMenu;
private JMenuItem exitItem;
private JMenuItem aboutItem;
// Purpose: Create an instance of TreasureGameView.
public static void main(String[] args)
{
new TreasureGameView();
}
// Purpose: Define the GUI window and panel layout for the game veiw.
public TreasureGameView()
{
setTitle("Treasure Hunt");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
west = new GameInfoPanel();
south = new LastMovePanel();
east = new LegendPanel();
center = new GameFieldPanel(west, south);
buildTitlePanel();
add(titlePanel, BorderLayout.NORTH);
add(west, BorderLayout.WEST);
add(south, BorderLayout.SOUTH);
add(east, BorderLayout.EAST);
add(center, BorderLayout.CENTER);
buildMenuBar();
pack();
setVisible(true);
}
// Purpose: Create the title shown at the top of the screen. Customize the look of the font.
public void buildTitlePanel()
{
title = new JLabel("Treasure Hunt");
title.setFont(new Font("Parchment", Font.PLAIN, 48));
titlePanel = new JPanel();
titlePanel.add(title);
}
// Purpose: Build the menu bar.
private void buildMenuBar()
{
menuBar = new JMenuBar();
buildFileMenu();
menuBar.add(fileMenu);
setJMenuBar(menuBar);
}
// Purpose: Build the components of the File menu.
private void buildFileMenu()
{
fileMenu = new JMenu("File");
exitItem = new JMenuItem("Exit");
exitItem.addActionListener(new ExitListener());
aboutItem = new JMenuItem("About");
aboutItem.addActionListener(new AboutListener());
fileMenu.add(exitItem);
fileMenu.add(aboutItem);
}
// Purpose: Action Listener for the exit menu item.
private class ExitListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
// Purpose: Action Listener for the about menu item.
private class AboutListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JOptionPane.showMessageDialog(null, "About\n" + "------------------------------\n\n" +
"Lead author: Ian Kligman\n" + "Play tester: Sean Kim\n" + "Version: 12/15/22\n");
}
}
}