-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstructionsPanel.java
More file actions
141 lines (124 loc) · 4.66 KB
/
InstructionsPanel.java
File metadata and controls
141 lines (124 loc) · 4.66 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
141
/**
* This class displays the instructions for the game. It contains a .gif
* image on a label (which instructions). It also contains 3 buttons (main
* menu, next/previous, and skip/play)
* <p>
* Priscilla was primarily responsible for the implementation of this class
*
* @author Priscilla Lee
* @version December 12 2014
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class InstructionsPanel extends JPanel {
//private instance vars
private JLabel instructions;
private JPanel buttonPanel;
private JButton mainMenu, nextPrevious, skipPlay;
private GamePanel gamePanel;
/**
* Constructor that takes GamePanel in as input.
*
* @param gp the GamePanel that will contain this panel
*/
public InstructionsPanel(GamePanel gp) {
gamePanel = gp;
//setting background & layout
setBackground(ColorScheme.background());
setLayout(new GridBagLayout());
//instructions label
ImageIcon icon = new ImageIcon("instructions.gif");
instructions = new JLabel(icon);
//main menu button
mainMenu = new JButton("<html><font color='white'>MAIN MENU</font></html>");
mainMenu.setFont(new Font("Calibri", Font.BOLD, 25));
mainMenu.setOpaque(true);
mainMenu.setBackground(ColorScheme.main());
mainMenu.addActionListener(new ButtonListener());
mainMenu.setBorder(BorderScheme.padding());
//nextPrevious button
nextPrevious = new JButton("<html><font color='white'>NEXT</font><html>");
nextPrevious.setFont(new Font("Calibri", Font.BOLD, 25));
nextPrevious.setOpaque(true);
nextPrevious.setBackground(ColorScheme.nextPrevious());
nextPrevious.setBorder(BorderScheme.padding());
nextPrevious.addActionListener(new ButtonListener());
//skipPlay button
skipPlay = new JButton("<html><font color='white'>SKIP</font><html>");
skipPlay.setFont(new Font("Calibri", Font.BOLD, 25));
skipPlay.setOpaque(true);
skipPlay.setBackground(ColorScheme.skipPlay());
skipPlay.setBorder(BorderScheme.padding());
skipPlay.addActionListener(new ButtonListener());
//button panel
buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(1,3));
buttonPanel.add(mainMenu);
buttonPanel.add(nextPrevious);
buttonPanel.add(skipPlay);
//add label + button panel with constraints
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
c.gridx = 0;
c.gridy = 0;
add(instructions, c);
c.weightx = 0.25;
c.gridy = 1;
c.ipady = 30;
add(buttonPanel, c);
}
/**
* Private inner class that indicates appropriate action button is clicked.
*/
private class ButtonListener implements ActionListener {
public void actionPerformed (ActionEvent event) {
if (event.getSource() == nextPrevious) {
if (nextPrevious.getText().equals("<html><font color='white'>NEXT</font><html>")) {
//then switch to 2nd image, change next to previous & skip to play
ImageIcon icon2 = new ImageIcon("instructions2.gif");
instructions.setIcon(icon2);
gamePanel.revalidate();
gamePanel.repaint();
revalidate();
repaint();
nextPrevious.setText("<html><font color='white'>PREVIOUS</font><html>");
skipPlay.setText("<html><font color='white'>PLAY</font><html>");
} else { //previous was clicked
//then switch back to 1st image, change previous to next & play to skip
ImageIcon icon2 = new ImageIcon("instructions.gif");
instructions.setIcon(icon2);
gamePanel.revalidate();
gamePanel.repaint();
revalidate();
repaint();
nextPrevious.setText("<html><font color='white'>NEXT</font><html>");
skipPlay.setText("<html><font color='white'>SKIP</font><html>");
}
}
else if (event.getSource() == skipPlay) {
try { //then play first level (construct new LevelPanel)
GridGraph gg = new GridGraph(1);
LevelPanel levelPan = new LevelPanel(gamePanel, gg);
gamePanel.add(levelPan);
gamePanel.remove(InstructionsPanel.this);
gamePanel.revalidate();
gamePanel.repaint();
revalidate();
repaint();
} catch (FileNotFoundException ex) {
System.out.println(ex);
}
} else { //mainMenu
gamePanel.add(new MainMenuPanel(gamePanel));
gamePanel.remove(InstructionsPanel.this);
gamePanel.revalidate();
gamePanel.repaint();
revalidate();
repaint();
}
}
}
}