-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGamePanel.java~
More file actions
65 lines (56 loc) · 1.86 KB
/
GamePanel.java~
File metadata and controls
65 lines (56 loc) · 1.86 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
/*
* GamePanel.java
* CS230 Final Project
* Author: Priscilla Lee
* Date: December 2 2014
*
* A GamePanel is meant to serve as the ultimate containing panel
* to display the full game. When the GameDriver is first run, a GamePanel
* is constructed with a title label and MainMenuPanel. As the game is played,
* any inner panels (LevelPanel, MainMenuPanel, InstructionsPanel) may
* simultaneously add new panels and remove themselves from their master
* GamePanel (to produce the illusion of "switching screens" to a new panel).
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class GamePanel extends JPanel{
//private instance vars
private JLabel title;
//constructor (GamePanel contains a title + an inner panel)
public GamePanel() {
//set background & layout & size
setBackground(ColorScheme.background());
setLayout(new GridBagLayout());
setPreferredSize(new Dimension(700,650));
setMinimumSize(new Dimension(700,650));
//title label
ImageIcon icon = new ImageIcon("path-finder.gif");
title = new JLabel(icon);
title.setBorder(BorderScheme.padding());
//MainMenuPanel
MainMenuPanel mmp = new MainMenuPanel(this);
//add components to this GamePanel (with constraints)
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
//add title
c.weighty = 0.5;
c.gridx = 0;
c.gridy = 0;
add(title,c);
//add mmp
add(mmp);
}
//override add method specifically for GamePanel with
//GridBagConstraints automatically included
public Component add(Component comp) {
//add components to this game panel (with constraints)
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.weighty = 2;
c.gridx = 0;
c.gridy = 1;
add(comp,c);
return comp;
}
}