-
Notifications
You must be signed in to change notification settings - Fork 0
/
mathGameGUI.java
98 lines (79 loc) · 4.07 KB
/
mathGameGUI.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
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class mathGameGUI extends javax.swing.JFrame {
private JButton submitAnswerButton;
private JTextField enterAnswerHere;
private JLabel answerLabel;
private JLabel problemLabel;
public mathGameGUI() {
initComponents();
setSize(400, 200);
setLocationRelativeTo(null);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Sophisticated Monkey Math Game");
}
private void initComponents() {
submitAnswerButton = new JButton();
enterAnswerHere = new JTextField();
answerLabel = new JLabel();
problemLabel = new JLabel();
mathGame aNumber = new mathGame();
problemLabel.setText(mathGame.number1 + " " + mathGame.operator +
" " + mathGame.number2 + " = ");
submitAnswerButton.setText("Submit");
submitAnswerButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
submitAnswerButtonActionPerformed(evt);
}
});
answerLabel.setText("Your Answer");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap())
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(problemLabel)
.addComponent(enterAnswerHere, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
.addGroup(layout.createSequentialGroup()
.addComponent(submitAnswerButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(answerLabel)
.addContainerGap(27, Short.MAX_VALUE))
));
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {submitAnswerButton, enterAnswerHere});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(problemLabel)
.addComponent(enterAnswerHere, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(submitAnswerButton)
.addComponent(answerLabel))
.addContainerGap(21, Short.MAX_VALUE))
);
}
private void submitAnswerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_convertButtonActionPerformed
Integer userInput = new Integer(enterAnswerHere.getText());
boolean answer = (mathGame.mathGameMonkey(userInput));
answerLabel.setText("Your answer is " + answer);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new mathGameGUI().setVisible(true);
}
});
}
}