-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstructionsMenu.java
More file actions
101 lines (87 loc) · 2.43 KB
/
InstructionsMenu.java
File metadata and controls
101 lines (87 loc) · 2.43 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
// InstructionsMenu.java
// Wendy Xu
// Displays real instructions
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
class InstructionsMenu extends JFrame implements ActionListener{
HelpMenu helpmenu;
InstructionsPanel instrucpanel;
javax.swing.Timer myTimer;
public InstructionsMenu(HelpMenu helpmenu){
super();
this.helpmenu = helpmenu;
setLayout(null);
instrucpanel = new InstructionsPanel(this);
instrucpanel.setSize(818,647);
instrucpanel.setLocation(0,0);
add(instrucpanel);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(818,647);
myTimer = new javax.swing.Timer(100,this);
myTimer.start();
}
public void actionPerformed(ActionEvent evt){
Object source = evt.getSource();
instrucpanel.draw();
}
public void mainMenu(){
helpmenu.setVisible(true);
helpmenu.mainMenu();
setVisible(false);
}
public static void main(String[] args){
InstructionsMenu menu = new InstructionsMenu(null);
}
}
class InstructionsPanel extends JPanel implements MouseListener, MouseMotionListener{
InstructionsMenu instrucmenu;
Image instrucPic = new ImageIcon("Images/Menus/Instructions.png").getImage();
Image instrucHover = new ImageIcon("Images/Menus/InstructionsHover.png").getImage();
boolean clicked;
int[] pos;
public void mouseClicked(MouseEvent evt){
clicked = true;
}
public void mouseExited(MouseEvent evt){}
public void mouseEntered(MouseEvent evt){}
public void mouseReleased(MouseEvent evt){
clicked = true;
}
public void mousePressed(MouseEvent evt){
clicked = false;
}
public void mouseMoved(MouseEvent evt){
pos = new int[]{evt.getX(),evt.getY()};
}
public void mouseDragged(MouseEvent evt){
pos = new int[]{evt.getX(),evt.getY()};
}
public InstructionsPanel(InstructionsMenu instrucmenu){
super();
setFocusable(true);
grabFocus();
addMouseListener(this);
addMouseMotionListener(this);
this.instrucmenu = instrucmenu;
clicked = false;
pos = new int[]{0,0};
}
public void draw(){
repaint();
}
public void paintComponent(Graphics g){
Rectangle mainmenuRect = new Rectangle(325,555,153,38);
if(mainmenuRect.contains(pos[0],pos[1])){ // mouse is in go back to main menu rect
g.drawImage(instrucHover,0,0,this); // draws hovering image
if(clicked == true){ // go back to main menu click
instrucmenu.mainMenu();
}
}
else{
g.drawImage(instrucPic,0,0,this);
}
}
}