From 46f83731f76ccb703307a9705c5cca93bfaf40d9 Mon Sep 17 00:00:00 2001 From: krolxon Date: Sat, 17 Feb 2024 19:59:03 +0530 Subject: [PATCH] add clear history button --- GFrame.java | 11 ++++++++++- History.java | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/GFrame.java b/GFrame.java index 14feb30..f03c154 100644 --- a/GFrame.java +++ b/GFrame.java @@ -79,7 +79,7 @@ public class GFrame extends JFrame { // History Text Field History history = new History(); JTextArea tHist = new JTextArea(); - tHist.setBounds(380, 50, 200, 290); + tHist.setBounds(380, 50, 200, 240); tHist.setEditable(false); tHist.setBorder(new RoundBtn(5)); tHist.setBackground(Color.decode("#2B2B2B")); @@ -91,6 +91,7 @@ public class GFrame extends JFrame { // Buttons JButton bEval = newButton("=", 250, 100, 100, 40); JButton bClear = newButton("CL", 180, 100, 60, 40); + JButton bClearHistory = newButton("Clear History", 380, 300, 200, 40); JButton bAdd = newButton("+", 250, 300, 100, 40); JButton bSub = newButton("-", 250, 250, 100, 40); JButton bMul = newButton("x", 250, 200, 100, 40); @@ -114,6 +115,7 @@ public class GFrame extends JFrame { // Add the buttons to the Frame this.add(bEval); this.add(bClear); + this.add(bClearHistory); this.add(bAdd); this.add(bSub); this.add(bMul); @@ -194,6 +196,13 @@ public class GFrame extends JFrame { } }); + bClearHistory.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + history.clearHistory(); + tHist.setText(""); + } + }); + bCut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String text = tf.getText(); diff --git a/History.java b/History.java index b1527ef..ef2807b 100644 --- a/History.java +++ b/History.java @@ -7,6 +7,10 @@ public class History { hist = new Vector(); } + public void clearHistory() { + hist.clear(); + } + public Vector getHistory() { return hist; }