Calculatorusingjava
Calculatorusingjava
Calculatorusingjava
*;
import java.awt.*;
import java.awt.event.*;
};
public CalculatorApplet() {
setTitle("Calculator");
setSize(300, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
displayField.setEditable(false);
add(displayField, BorderLayout.NORTH);
buttons[i].addActionListener(this);
buttonPanel.add(buttons[i]);
add(buttonPanel, BorderLayout.CENTER);
if ("0123456789".contains(command)) {
displayField.setText(displayField.getText() + command);
} else if (command.equals("C")) {
displayField.setText("");
} else if (command.equals("=")) {
try {
displayField.setText(result);
displayField.setText("Division by zero");
} else {
if (tokens.length % 2 == 0) {
switch (operator) {
case "+":
result += operand;
break;
case "-":
result -= operand;
break;
case "*":
result *= operand;
break;
case "/":
if (operand == 0) {
result /= operand;
break;
default:
return Double.toString(result);
SwingUtilities.invokeLater(() -> {
calculator.setVisible(true);
});