add clear history button

This commit is contained in:
krolxon 2024-02-17 19:59:03 +05:30
parent 8a095b2b16
commit 46f83731f7
2 changed files with 14 additions and 1 deletions

View File

@ -79,7 +79,7 @@ public class GFrame extends JFrame {
// History Text Field // History Text Field
History history = new History(); History history = new History();
JTextArea tHist = new JTextArea(); JTextArea tHist = new JTextArea();
tHist.setBounds(380, 50, 200, 290); tHist.setBounds(380, 50, 200, 240);
tHist.setEditable(false); tHist.setEditable(false);
tHist.setBorder(new RoundBtn(5)); tHist.setBorder(new RoundBtn(5));
tHist.setBackground(Color.decode("#2B2B2B")); tHist.setBackground(Color.decode("#2B2B2B"));
@ -91,6 +91,7 @@ public class GFrame extends JFrame {
// Buttons // Buttons
JButton bEval = newButton("=", 250, 100, 100, 40); JButton bEval = newButton("=", 250, 100, 100, 40);
JButton bClear = newButton("CL", 180, 100, 60, 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 bAdd = newButton("+", 250, 300, 100, 40);
JButton bSub = newButton("-", 250, 250, 100, 40); JButton bSub = newButton("-", 250, 250, 100, 40);
JButton bMul = newButton("x", 250, 200, 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 // Add the buttons to the Frame
this.add(bEval); this.add(bEval);
this.add(bClear); this.add(bClear);
this.add(bClearHistory);
this.add(bAdd); this.add(bAdd);
this.add(bSub); this.add(bSub);
this.add(bMul); 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() { bCut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
String text = tf.getText(); String text = tf.getText();

View File

@ -7,6 +7,10 @@ public class History {
hist = new Vector<String>(); hist = new Vector<String>();
} }
public void clearHistory() {
hist.clear();
}
public Vector<String> getHistory() { public Vector<String> getHistory() {
return hist; return hist;
} }