From f830cecc6b67008292fe886313f4b6b1907f136a Mon Sep 17 00:00:00 2001 From: angel Date: Fri, 9 Jan 2026 09:19:34 -0600 Subject: [PATCH] Update src/main/java/dev/sillyangel/calc/Calculator.java --- .../java/dev/sillyangel/calc/Calculator.java | 44 ++----------------- 1 file changed, 3 insertions(+), 41 deletions(-) diff --git a/src/main/java/dev/sillyangel/calc/Calculator.java b/src/main/java/dev/sillyangel/calc/Calculator.java index 99b9954..ce8ab22 100644 --- a/src/main/java/dev/sillyangel/calc/Calculator.java +++ b/src/main/java/dev/sillyangel/calc/Calculator.java @@ -180,6 +180,8 @@ public class Calculator extends JFrame implements KeyListener { JMenuItem Exit = new JMenuItem("Exit"); Exit.addActionListener(e -> System.exit(1)); Exit.setMnemonic('E'); + JMenuItem hmi = new JMenuItem("View History"); + hmi.addActionListener(e -> calculatorUtils.showHistoryDialog()); JMenuItem about = new JMenuItem("About"); about.setMnemonic('A'); @@ -338,47 +340,7 @@ public class Calculator extends JFrame implements KeyListener { // History dialog - private void showHistoryDialog() { - JDialog historyDialog = new JDialog(this, "Calculation History", true); - historyDialog.setSize(500, 400); - historyDialog.setLocationRelativeTo(this); - historyDialog.setLayout(new BorderLayout(10, 10)); - - List historyList = history.getCalculationHistory(); - - if (historyList.isEmpty()) { - JLabel emptyLabel = new JLabel("No calculation history yet", SwingConstants.CENTER); - emptyLabel.setFont(new Font("Segoe UI", Font.PLAIN, 14)); - historyDialog.add(emptyLabel, BorderLayout.CENTER); - } else { - JTextArea historyTextArea = new JTextArea(); - historyTextArea.setEditable(false); - historyTextArea.setFont(new Font("Monospaced", Font.PLAIN, 12)); - - StringBuilder historyText = new StringBuilder(); - for (String entry : historyList) { - historyText.append(entry).append("\n"); - } - historyTextArea.setText(historyText.toString()); - - JScrollPane scrollPane = new JScrollPane(historyTextArea); - historyDialog.add(scrollPane, BorderLayout.CENTER); - - // Status label - JLabel statusLabel = new JLabel("Total calculations: " + historyList.size()); - statusLabel.setBorder(new EmptyBorder(5, 10, 5, 10)); - historyDialog.add(statusLabel, BorderLayout.NORTH); - } - - JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - JButton closeButton = new JButton("Close"); - closeButton.addActionListener(e -> historyDialog.dispose()); - buttonPanel.add(closeButton); - - historyDialog.add(buttonPanel, BorderLayout.SOUTH); - historyDialog.setVisible(true); - } - + private void clearHistoryAction() { int result = JOptionPane.showConfirmDialog(this, "Are you sure you want to clear all calculation history?",