Update src/main/java/dev/sillyangel/calc/Calculator.java
Some checks failed
Build the Jar / build (push) Failing after 7s
Some checks failed
Build the Jar / build (push) Failing after 7s
This commit is contained in:
@@ -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<String> 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?",
|
||||
|
||||
Reference in New Issue
Block a user