-
Notifications
You must be signed in to change notification settings - Fork 0
/
Instructions.java
executable file
·201 lines (167 loc) · 4.78 KB
/
Instructions.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;
public class Instructions extends JPanel implements MouseListener {
//declaration and initialization
BufferedImage mode1, mode2;
JLabel back = new JLabel();
JLabel next = new JLabel();
JLabel backhover = new JLabel();
JLabel nexthover = new JLabel();
ImageIcon backButton, nextButton, nextButtonhover, backButtonhover,backButtonSmall,backButtonhoverSmall;
//for animation
int x = 1366;
int y = 0;
int screen = 1;
{
try {
// Reading images from storage
mode1 = ImageIO.read(new File("resources\\instruction1Background.jpg"));
mode2 = ImageIO.read(new File("resources\\instruction2Background.jpg"));
backButton = new ImageIcon("resources\\backLarge.png");
backButtonSmall = new ImageIcon("resources\\back.png");
nextButton = new ImageIcon("resources\\next.png");
backButtonhover = new ImageIcon("resources\\backhLarge.png");
backButtonhoverSmall = new ImageIcon("resources\\backh.png");
nextButtonhover = new ImageIcon("resources\\nexth.png");
}
// Catching exception
catch (IOException e) {
e.printStackTrace();
System.out.print("Image not found");
}
//Setting button properties
back.setIcon(backButton);
add(back);
back.setBounds(0, 660, 100, 100);
back.addMouseListener(this);
next.setIcon(nextButton);
add(next);
next.setBounds(900, 600, 70, 70);
next.addMouseListener(this);
// Setting layout null
setLayout(null);
}
// Paint Component method
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
Color color=new Color(255,255,255,0);
setBackground(color);
// Drawing image to panel in full height and width
if (screen == 1)
//mode 1 instructions
g2d.drawImage(mode1, x, y, getWidth(), getHeight(), null);
if (screen == 2)
//moede2
g2d.drawImage(mode2, x, y, getWidth(), getHeight(), null);
//animation
if (x > 0) {
x -= 100;
}
if (x <= 0) {
x = 0;
}
try {
Thread.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
}
repaint();
}// Paint Component ends
@Override
public void mouseClicked(MouseEvent e) {
//Back button to end instructions
if (e.getSource() == back) {
Menu.fm.dispose();
}
//mode 2 instruction
if (e.getSource() == next) {
if (screen == 1) {
screen = 2;
next.setIcon(backButtonSmall);
next.setBounds(400, 600, 70, 70);
} else
//mode1 instructions
if (screen == 2) {
screen = 1;
next.setIcon(nextButton);
next.setBounds(900, 600, 70, 70);
}
}
}
//adding hover effect
@Override
public void mouseEntered(MouseEvent e) {
if (e.getSource() == back) {
back.setIcon(backButtonhover);
}
if (e.getSource() == next) {
if(screen==1)
next.setIcon(nextButtonhover);
if(screen==2)
next.setIcon(backButtonhoverSmall);
}
}
//restoring images to make hover effect
@Override
public void mouseExited(MouseEvent e) {
if (e.getSource() == back) {
back.setIcon(backButton);
}
if (e.getSource() == next) {
if(screen==1)
next.setIcon(nextButton);
if(screen==2)
next.setIcon(backButtonSmall);
}
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
//Adding Escape key action to go back to menu
Action Escape = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
Menu.fm.dispose();
}
};
//Adding Left key action to go to mode1
Action Left = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
screen = 1;
next.setIcon(nextButton);
next.setBounds(900, 600, 70, 70);
}
};
//Adding Right key action to go to mode1
Action Right = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
screen = 2;
next.setIcon(backButtonSmall);
next.setBounds(400, 600, 70, 70);
}
};
//Adding Keyactions through Key Bindings
{
InputMap mp=this.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
mp.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0,false), "keyEscape");
mp.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT,0,false), "keyRight");
mp.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT,0,false), "keyLeft");
ActionMap act=this.getActionMap();
act.put("keyEscape", Escape);
act.put("keyRight", Right);
act.put("keyLeft", Left);
}
}// Class Ends