-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestInfoFrame.java
More file actions
155 lines (128 loc) · 5.5 KB
/
TestInfoFrame.java
File metadata and controls
155 lines (128 loc) · 5.5 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package src.classSrc;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.event.MouseInputAdapter;
import java.awt.event.MouseEvent;
import java.awt.Component.*;
public class TestInfoFrame extends JFrame {
private ImageIcon backgroundImg;
private JLabel backgroundLabel;
private JPanel backgroundPanel;
private JButton infoButton;
private JButton startButton;
private JButton menuButton;
private SortInfoReader reader;
private ArrayList<String> quizAnswer = new ArrayList<String>();
private int[][] visit = new int[3][30];
private String info = "Here's the rules:" + "\n" +
"1. There are 5 questions in this section" + "\n" +
"2. Each question has 20 points" + "\n" +
"3. There are 3 type of question in this section: Multiple Choice, True Or False"
+ "\n" +
" and Cloze" + "\n" +
"4. There's no time limit. Focus on your question and try your best!";
public TestInfoFrame() {
// GUI init
setTitle("ALGORITHM VISUALIZATION");
setSize(1000, 600);
setLayout(null);
// set background
backgroundImg = new ImageIcon("src/imageSrc/Background.png");
backgroundLabel = new JLabel(backgroundImg);
backgroundLabel.setBounds(0, 0, getWidth(), getHeight());
backgroundPanel = (JPanel) this.getContentPane();
backgroundPanel.setOpaque(false);
getLayeredPane().add(backgroundLabel, Integer.valueOf(Integer.MIN_VALUE));
// set listener
ActionListener listener = new ButtonEventListener();
// set button
infoButton = new JButton(new ImageIcon("src/imageSrc/uncheckedPrecautions.png"));
infoButton.setBounds(340, 140, 300, 100);
infoButton.setOpaque(false);
infoButton.setContentAreaFilled(false);
infoButton.setBorderPainted(false);
infoButton.addActionListener(listener);
startButton = new JButton(new ImageIcon("src/imageSrc/uncheckedStart.png"));
startButton.setBounds(337, 400, 300, 125);
startButton.setOpaque(false);
startButton.setContentAreaFilled(false);
startButton.setBorderPainted(false);
startButton.addActionListener(listener);
menuButton = new JButton(new ImageIcon("src/imageSrc/uncheckedMenu.png"));
menuButton.setBounds(885, 1, 100, 50);
menuButton.setOpaque(false);
menuButton.setContentAreaFilled(false);
menuButton.setFocusPainted(false);
menuButton.setBorderPainted(false);
menuButton.addActionListener(listener);
// add new elements to frame
add(infoButton);
add(startButton);
add(menuButton);
// set mouse listener
ButtonListener buttonListener = new ButtonListener();
// addMouseListener(infoButtonListener); // press、release、click、enter、exit
infoButton.addMouseMotionListener(buttonListener); // move、drag
startButton.addMouseMotionListener(buttonListener);
menuButton.addMouseMotionListener(buttonListener);
addMouseMotionListener(buttonListener);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setResizable(false);
setVisible(true);
}
private class ButtonListener extends MouseInputAdapter {
public void mouseMoved(MouseEvent e) {
if (e.getSource() == infoButton) {
infoButton.setIcon(new ImageIcon("src/imageSrc/Precautions.png"));
} else {
infoButton.setIcon(new ImageIcon("src/imageSrc/uncheckedPrecautions.png"));
}
if (e.getSource() == menuButton) {
menuButton.setIcon(new ImageIcon("src/imageSrc/Menu.png"));
} else {
menuButton.setIcon(new ImageIcon("src/imageSrc/uncheckedMenu.png"));
}
if (e.getSource() == startButton) {
startButton.setIcon(new ImageIcon("src/imageSrc/Start.png"));
} else {
startButton.setIcon(new ImageIcon("src/imageSrc/uncheckedStart.png"));
}
repaint();
}
}
private class ButtonEventListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == infoButton) { // info
JOptionPane.showMessageDialog(null, info, "Announcement!", JOptionPane.DEFAULT_OPTION);
} else if (e.getSource() == startButton) { // start testing
Random random = new Random();
int start = random.nextInt(3) + 1;
// start
switch (start) {
case 1: // single
MultipleChoice typeSingle = new MultipleChoice(visit, 1, 0);
setVisible(false);
break;
case 2: // yes/no
TrueOrFalse trueOrFalse = new TrueOrFalse(visit, 1, 0);
setVisible(false);
break;
case 3: // insert
Cloze insertTest = new Cloze(visit, 1, 0);
setVisible(false);
break;
}
setVisible(false);
} else { // back to menu
new Menu();
setVisible(false);
}
}
}
}