|
|
| It is currently Sun Dec 14, 2025 10:30 am |
public void clearEntry() // Implementation for clear entry
📋 Overview A scientific calculator built in Java Swing with support for basic arithmetic, trigonometric functions, logarithms, exponents, and more. This is a complete, ready-to-run project. 📁 Project Structure ScientificCalculator/ ├── src/ │ ├── ScientificCalculator.java │ ├── CalculatorEngine.java │ └── CalculatorUI.java ├── README.md └── build.bat (Windows) / build.sh (Linux/Mac) 💻 Complete Source Code 1. ScientificCalculator.java (Main Class) import javax.swing.*; import javax.swing.border.*; import java.awt.*; import java.awt.event.*; import java.math.BigDecimal; import java.math.RoundingMode; public class ScientificCalculator extends JFrame private JTextField displayField; private JPanel buttonPanel; private CalculatorEngine engine; private boolean isDegree = true; // true = DEG, false = RAD
public ScientificCalculator() engine = new CalculatorEngine(); initializeUI(); setTitle("Scientific Calculator"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setResizable(false); pack(); setLocationRelativeTo(null); scientific calculator source code in java free download
private class ButtonClickListener implements ActionListener private String command; public ButtonClickListener(String command) this.command = command; @Override public void actionPerformed(ActionEvent e) String currentText = displayField.getText(); switch (command) ": case "floor": case "ceil": case "!": case "%": case "π": case "e": case "rand": String result = engine.calculateUnary(command, currentText, isDegree); displayField.setText(result); break; default: // Handle digits, operators, and parentheses if (currentText.equals("0") && command.matches("[0-9]")) displayField.setText(command); else if (command.equals(".") && !currentText.contains(".")) displayField.setText(currentText + command); else if (command.matches("[0-9+\\-*/()]")) displayField.setText(currentText + command); else displayField.setText(currentText + command); break;
private JButton createStyledButton(String text) text.equals(".")) button.setBackground(Color.WHITE); else if (text.matches("[+\\-*/%] public void clearEntry() // Implementation for clear entry
public void clear() memory = 0;
private double evaluateExpression(String expression) return new ExpressionEvaluator().evaluate(expression); ScientificCalculator
private double factorial(int n) n == 1) return 1; double result = 1; for (int i = 2; i <= n; i++) result *= i; return result;
(Logic Engine) import java.math.BigDecimal; import java.math.RoundingMode; import java.util.Stack; public class CalculatorEngine private double memory; private boolean degreeMode = true;
|
6502.org is an ongoing project by Mike Naberezny and contributors. © 2026 Grand Node. All rights reserved. |
|