-
Notifications
You must be signed in to change notification settings - Fork 0
/
InstructionFrame.java
executable file
·147 lines (119 loc) · 3.38 KB
/
InstructionFrame.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
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
142
143
144
145
146
147
/*
* Mouse Mouse - coded by Emmett Butler, Spring 2010
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
public class InstructionFrame extends JFrame {
private InstructionPanel ins = new InstructionPanel();
private JButton cont = new JButton("Start the Game!");
private boolean contClicked = false;
InstructionFrame() {
setSize(810, 455);
setResizable(false);
setTitle("Mouse Mouse - How to Play");
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Add opening panel
ins.add(cont, BorderLayout.SOUTH);
add(ins);
// When button is clicked, set contClicked true
cont.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
MouseMouse mm = new MouseMouse();
mm.setVisible(true);
}
});
}
}
class InstructionPanel extends JPanel {
private URL path;
private ImageIcon imageIcon;
private Image howto;
InstructionPanel() {
path = getClass().getResource("images/howto.png");
if(path != null){
imageIcon = new ImageIcon(path);
howto = imageIcon.getImage();
}
setLayout(new BorderLayout());
}
protected void paintComponent(Graphics g) {
g.drawImage(howto, 0, 0, this);
}
}
class TitleFrame extends JFrame {
private TitlePanel tp = new TitlePanel();
private JButton cont = new JButton("Start");
private boolean contClicked = false;
TitleFrame() {
setSize(797, 550);
setResizable(false);
setTitle("Mouse Mouse");
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Add opening panel
tp.add(cont, BorderLayout.SOUTH);
add(tp);
// When button is clicked, set contClicked true
cont.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
InstructionFrame inst = new InstructionFrame();
inst.setVisible(true);
}
});
}
}
class TitlePanel extends JPanel {
private ImageIcon imageIcon;
private Image image;
private URL path;
TitlePanel() {
path = getClass().getResource("images/title.png");
if(path != null){
imageIcon = new ImageIcon(path);
image = imageIcon.getImage();
}
setLayout(new BorderLayout());
}
protected void paintComponent(Graphics g) {
g.drawImage(image, 0, 0, this);
}
}
class OptionFrame extends JFrame {
JButton scoreButton = new JButton("Scores");
JButton newButton = new JButton("New Game");
JButton quitButton = new JButton("Quit");
OptionFrame(){
setLayout(new FlowLayout());
setSize(300, 60);
setResizable(false);
setTitle("Mouse Mouse - Options");
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
newButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
MouseMouse mm = new MouseMouse();
}
});
scoreButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
ScoreFrame sf = new ScoreFrame();
}
});
quitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
add(newButton);
add(scoreButton);
add(quitButton);
setVisible(true);
}
}