这是一个简单的计算器,代码如下:
import java.awt.*;
import java.awt.event.*;
public class Homework2 extends Frame implements ActionListener,KeyListener
{
Label label;
Button n1,n2,n3,n4,n5,n6,n7,n8,n9,n0,addition,subtraction,multiplication,division,equle,C;
Font f;
char ch;
String regA,regB;
char op;
double sum;
Homework2()
{
setTitle("简易计算器");
setLayout(null);
regA=new String("");
regB=new String("");
label=new Label("0",Label.RIGHT);
label.setBackground(Color.black);
f=new Font("arial",Font.BOLD,12);
label.setForeground(Color.white);
label.setFont(f);
n1=new Button("1");
n2=new Button("2");
n3=new Button("3");
n4=new Button("4");
n5=new Button("5");
n6=new Button("6");
n7=new Button("7");
n8=new Button("8");
n9=new Button("9");
n0=new Button("0");
addition=new Button("+");
multiplication=new Button("×");
subtraction=new Button("-");
division=ne