T
T
*;
import java.awt.event.*;
Calculator() {
setTitle("Calculator");
setSize(420, 550);
setLayout(null);
setVisible(true);
b0 = new Button("0");
b1 = new Button("1");
b2 = new Button("2");
b3 = new Button("3");
b4 = new Button("4");
b5 = new Button("5");
b6 = new Button("6");
b7 = new Button("7");
b8 = new Button("8");
b9 = new Button("9");
b0.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
addButton.addActionListener(this);
subButton.addActionListener(this);
mulButton.addActionListener(this);
divButton.addActionListener(this);
eqButton.addActionListener(this);
clrButton.addActionListener(this);
panel.add(b1);
panel.add(b2);
panel.add(b3);
panel.add(addButton);
panel.add(b4);
panel.add(b5);
panel.add(b6);
panel.add(subButton);
panel.add(b7);
panel.add(b8);
panel.add(b9);
panel.add(mulButton);
panel.add(new Label()); // Empty space
panel.add(b0);
panel.add(eqButton);
panel.add(divButton);
add(panel);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
}
});
}
@Override
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();