-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuClass.java
More file actions
65 lines (57 loc) · 1.93 KB
/
MenuClass.java
File metadata and controls
65 lines (57 loc) · 1.93 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
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JPanel;
public class MenuClass extends JPanel implements ActionListener {
// Creates variables to be toggled when buttons are clicked
boolean showInstructions = false;
boolean playHit = false;
/** JPanel Constructor */
public MenuClass() {
// Creates JPanel
setBackground(Color.BLACK);
setLayout(null);
setFocusable(true);
// Creates JButtons
JButton playButton = new JButton("Play");
JButton helpButton = new JButton("Instructions");
playButton.setBounds(300, 350, 200, 50);
helpButton.setBounds(300, 410, 200, 50);
playButton.addActionListener(this);
helpButton.addActionListener(this);
add(playButton);
add(helpButton);
}
/** Listens for any presses of the buttons and responds accordingly */
public void actionPerformed(ActionEvent e) {
String actionCommand = e.getActionCommand();
// Changes a variable to indicate play button was pressed
if(actionCommand.equals("Play"))
playHit = true;
// Calls for instructions to be displayed
else if(actionCommand.equals("Instructions")) {
showInstructions = true;
repaint();
}
}
/** Creates title text and instructions */
public void paintComponent(Graphics g) {
super.paintComponent(g);
// Creates title
g.setColor(Color.WHITE);
g.setFont(new Font("TimesRoman", Font.PLAIN, 72));
g.drawString("Dodge the Ball", 175, 200);
// Creates instructions
if(showInstructions) {
g.setColor(Color.WHITE);
g.setFont(new Font("TimesRoman", Font.PLAIN, 24));
g.drawString("You are the white ball.", 300, 600);
g.drawString("Move with WASD or arrow keys.", 300, 625);
g.drawString("You have three lives.", 300, 650);
g.drawString("Don't touch the red balls!", 300, 675);
}
}
}