-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDivision.java
More file actions
189 lines (160 loc) · 5.26 KB
/
Division.java
File metadata and controls
189 lines (160 loc) · 5.26 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
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
package mathPractice;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
public class Division extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Division frame = new Division();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
private int counter;
public int getCounter() {
return counter;
}
public void setCounter(int counter) {
this.counter = counter;
}
private JTextField textNum1;
private JTextField textNum2;
private JTextField answer ;
private JTextField scoreBoard;
private JLabel levelDisplayer;
int a;
int num1,num2;
public void starter(int a) {
Random number = new Random();
if (a <=10) {
levelDisplayer.setText("Level 1:");
num1 = number.nextInt(5);
num2 = number.nextInt(5);
}
else if (a <= 15) {
a=0;
JOptionPane.showMessageDialog(null, "Congrats you have passed level 1!");
num1 = number.nextInt(10);
num2 = number.nextInt(10);}
else {
a=0;
levelDisplayer.setText("Level 2:");
num1 = number.nextInt(15);
num2 = number.nextInt(15);
}
textNum1.setText(Integer.toString(num1));
textNum2.setText(Integer.toString(num2));
scoreBoard.setText(Integer.toString(getCounter()));
answer.setText("");
}
public Division() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 700, 449);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
levelDisplayer = new JLabel("");
levelDisplayer.setFont(new Font("Tahoma", Font.PLAIN, 25));
levelDisplayer.setBounds(288, 370, 131, 29);
contentPane.add(levelDisplayer);
textNum1 = new JTextField();
textNum1.setHorizontalAlignment(SwingConstants.CENTER);
textNum1.setFont(new Font("Tahoma", Font.PLAIN, 55));
textNum1.setBounds(55, 88, 200, 75);
contentPane.add(textNum1);
textNum1.setColumns(10);
textNum2 = new JTextField();
textNum2.setHorizontalAlignment(SwingConstants.CENTER);
textNum2.setFont(new Font("Tahoma", Font.PLAIN, 55));
textNum2.setColumns(10);
textNum2.setBounds(438, 88, 200, 75);
contentPane.add(textNum2);
JLabel lblNewLabel = new JLabel("-");
lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 60));
lblNewLabel.setBounds(325, 93, 89, 60);
contentPane.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("Answer:");
lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 25));
lblNewLabel_1.setBounds(204, 215, 161, 64);
contentPane.add(lblNewLabel_1);
answer = new JTextField();
answer.setHorizontalAlignment(SwingConstants.CENTER);
answer.setFont(new Font("Tahoma", Font.PLAIN, 18));
answer.setBounds(325, 229, 150, 48);
contentPane.add(answer);
answer.setColumns(10);
JProgressBar levelProgress = new JProgressBar();
levelProgress.setString("Progress");
levelProgress.setValue(0);
levelProgress.setMaximum(10);
levelProgress.setBounds(398, 370, 249, 29);
contentPane.add(levelProgress);
scoreBoard = new JTextField();
scoreBoard.setHorizontalAlignment(SwingConstants.CENTER);
scoreBoard.setFont(new Font("Tahoma", Font.PLAIN, 31));
scoreBoard.setBounds(26, 339, 106, 60);
contentPane.add(scoreBoard);
scoreBoard.setColumns(10);
JLabel lblNewLabel_2 = new JLabel("Correct Answers");
lblNewLabel_2.setFont(new Font("Tahoma", Font.PLAIN, 15));
lblNewLabel_2.setBounds(26, 316, 106, 14);
contentPane.add(lblNewLabel_2);
JLabel display = new JLabel("");
display.setHorizontalAlignment(SwingConstants.CENTER);
display.setFont(new Font("Serif", Font.BOLD, 20));
display.setBounds(171, 174, 378, 39);
contentPane.add(display);
JButton btnCheck = new JButton("Check");
btnCheck.setFont(new Font("Tahoma", Font.PLAIN, 20));
starter(1);
btnCheck.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (Integer.parseInt(answer.getText()) == Math.abs(num1-num2)) {
setCounter(getCounter()+1);
a++;
levelProgress.setValue(a);
display.setText("Awesome Job!");
starter(getCounter());
}
else {
a=0;
display.setText("Booo! Incorrect");
levelProgress.setValue(a);
setCounter(0);
starter(getCounter());
}
}
});
btnCheck.setBounds(257, 300, 150, 50);
contentPane.add(btnCheck);
JLabel lblMultiply = new JLabel("Subtraction");
lblMultiply.setForeground(new Color(0, 0, 139));
lblMultiply.setHorizontalAlignment(SwingConstants.CENTER);
lblMultiply.setFont(new Font("Serif", Font.BOLD, 52));
lblMultiply.setBounds(156, 11, 399, 64);
contentPane.add(lblMultiply);
}
}