Krolyxon
Commit 46f8373

Branches

Refs →

jcal46f8373

add clear history button

Author
krolxon
Date
2024-02-17 19:59 +0530
Parent
8a095b2
Commit
46f83731f76ccb703307a9705c5cca93bfaf40d9

+14 −1

2 files changed

  1. M GFrame.java +10 −1
  2. M History.java +4 −0
M GFrame.java View
@@ -79,7 +79,7 @@ public class GFrame extends JFrame {
7979 // History Text Field
8080 History history = new History();
8181 JTextArea tHist = new JTextArea();
82− tHist.setBounds(380, 50, 200, 290);
82+ tHist.setBounds(380, 50, 200, 240);
8383 tHist.setEditable(false);
8484 tHist.setBorder(new RoundBtn(5));
8585 tHist.setBackground(Color.decode("#2B2B2B"));
@@ -91,6 +91,7 @@ public class GFrame extends JFrame {
9191 // Buttons
9292 JButton bEval = newButton("=", 250, 100, 100, 40);
9393 JButton bClear = newButton("CL", 180, 100, 60, 40);
94+ JButton bClearHistory = newButton("Clear History", 380, 300, 200, 40);
9495 JButton bAdd = newButton("+", 250, 300, 100, 40);
9596 JButton bSub = newButton("-", 250, 250, 100, 40);
9697 JButton bMul = newButton("x", 250, 200, 100, 40);
@@ -114,6 +115,7 @@ public class GFrame extends JFrame {
114115 // Add the buttons to the Frame
115116 this.add(bEval);
116117 this.add(bClear);
118+ this.add(bClearHistory);
117119 this.add(bAdd);
118120 this.add(bSub);
119121 this.add(bMul);
@@ -194,6 +196,13 @@ public class GFrame extends JFrame {
194196 }
195197 });
196198
199+ bClearHistory.addActionListener(new ActionListener() {
200+ public void actionPerformed(ActionEvent e) {
201+ history.clearHistory();
202+ tHist.setText("");
203+ }
204+ });
205+
197206 bCut.addActionListener(new ActionListener() {
198207 public void actionPerformed(ActionEvent e) {
199208 String text = tf.getText();
M History.java View
@@ -7,6 +7,10 @@ public class History {
77 hist = new Vector<String>();
88 }
99
10+ public void clearHistory() {
11+ hist.clear();
12+ }
13+
1014 public Vector<String> getHistory() {
1115 return hist;
1216 }