jcal46f8373
add clear history button
+14 −1
2 files changed
- M GFrame.java +10 −1
- M History.java +4 −0
| @@ -79,7 +79,7 @@ public class GFrame extends JFrame { | |||
| 79 | 79 | // History Text Field | |
| 80 | 80 | History history = new History(); | |
| 81 | 81 | JTextArea tHist = new JTextArea(); | |
| 82 | − | tHist.setBounds(380, 50, 200, 290); | |
| 82 | + | tHist.setBounds(380, 50, 200, 240); | |
| 83 | 83 | tHist.setEditable(false); | |
| 84 | 84 | tHist.setBorder(new RoundBtn(5)); | |
| 85 | 85 | tHist.setBackground(Color.decode("#2B2B2B")); | |
| @@ -91,6 +91,7 @@ public class GFrame extends JFrame { | |||
| 91 | 91 | // Buttons | |
| 92 | 92 | JButton bEval = newButton("=", 250, 100, 100, 40); | |
| 93 | 93 | JButton bClear = newButton("CL", 180, 100, 60, 40); | |
| 94 | + | JButton bClearHistory = newButton("Clear History", 380, 300, 200, 40); | |
| 94 | 95 | JButton bAdd = newButton("+", 250, 300, 100, 40); | |
| 95 | 96 | JButton bSub = newButton("-", 250, 250, 100, 40); | |
| 96 | 97 | JButton bMul = newButton("x", 250, 200, 100, 40); | |
| @@ -114,6 +115,7 @@ public class GFrame extends JFrame { | |||
| 114 | 115 | // Add the buttons to the Frame | |
| 115 | 116 | this.add(bEval); | |
| 116 | 117 | this.add(bClear); | |
| 118 | + | this.add(bClearHistory); | |
| 117 | 119 | this.add(bAdd); | |
| 118 | 120 | this.add(bSub); | |
| 119 | 121 | this.add(bMul); | |
| @@ -194,6 +196,13 @@ public class GFrame extends JFrame { | |||
| 194 | 196 | } | |
| 195 | 197 | }); | |
| 196 | 198 | ||
| 199 | + | bClearHistory.addActionListener(new ActionListener() { | |
| 200 | + | public void actionPerformed(ActionEvent e) { | |
| 201 | + | history.clearHistory(); | |
| 202 | + | tHist.setText(""); | |
| 203 | + | } | |
| 204 | + | }); | |
| 205 | + | ||
| 197 | 206 | bCut.addActionListener(new ActionListener() { | |
| 198 | 207 | public void actionPerformed(ActionEvent e) { | |
| 199 | 208 | String text = tf.getText(); | |
| @@ -7,6 +7,10 @@ public class History { | |||
| 7 | 7 | hist = new Vector<String>(); | |
| 8 | 8 | } | |
| 9 | 9 | ||
| 10 | + | public void clearHistory() { | |
| 11 | + | hist.clear(); | |
| 12 | + | } | |
| 13 | + | ||
| 10 | 14 | public Vector<String> getHistory() { | |
| 11 | 15 | return hist; | |
| 12 | 16 | } | |