a
a
*;
import java.awt.event.*;
// Calculator variables
double num1 = 0, num2 = 0, result = 0;
char operator;
CalculatorAWT() {
// Frame setup
frame = new Frame("Calculator");
frame.setSize(420, 550);
frame.setLayout(null);
frame.setVisible(true);
frame.setResizable(false);
frame.setBackground(Color.PINK); // Set the background to pink
// Textfield setup
textfield = new TextField();
textfield.setBounds(50, 25, 300, 50);
textfield.setFont(myFont);
textfield.setEditable(false);
// Function buttons
addButton = new Button("+");
subButton = new Button("-");
mulButton = new Button("*");
divButton = new Button("/");
decButton = new Button(".");
equButton = new Button("=");
delButton = new Button("Del");
clrButton = new Button("Clr");
functionButtons[0] = addButton;
functionButtons[1] = subButton;
functionButtons[2] = mulButton;
functionButtons[3] = divButton;
functionButtons[4] = decButton;
functionButtons[5] = equButton;
functionButtons[6] = delButton;
functionButtons[7] = clrButton;
// Button positions
delButton.setBounds(150, 430, 100, 50);
clrButton.setBounds(250, 430, 100, 50);
@Override
public void actionPerformed(ActionEvent e) {
switch (operator) {
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
result = num1 / num2;
break;
}
textfield.setText(String.valueOf(result));
num1 = result;
}