该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
import java.awt.*;
import java.awt.event.*;
public class Calcu extends Frame implements ActionListener{
private TextField Enter;
private Button N0,N1,N2,N3,N4,N5,N6,N7,N8,N9,N10,N11,N12,N13,N14,N15,N16;
String m="0";
Boolean Dots=true,clickable=true;
short prekey=-1;
double a;
//构造函数
public Calcu(){
super("马叶计算器");
setPreferredSize(new Dimension(200,200));
setBounds(200,200,200,200);
N0=new Button("0");
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");
N10=new Button("+");
N11=new Button("-");
N12=new Button("*");
N13=new Button("/");
N14=new Button(".");
N15=new Button("=");
N16=new Button("清零");
Enter=new TextField(30);
Panel buttons=new Panel();
buttons.setLayout(new GridLayout(4,4));
buttons.add(N7);
N7.addActionListener(this);
buttons.add(N8);
N8.addActionListener(this);
buttons.add(N9);
N9.addActionListener(this);
buttons.add(N10);
N10.addActionListener(this);
buttons.add(N4);
N4.addActionListener(this);
buttons.add(N5);
N5.addActionListener(this);
buttons.add(N6);
N6.addActionListener(this);
buttons.add(N11);
N11.addActionListener(this);
buttons.add(N1);
N1.addActionListener(this);
buttons.add(N2);
N2.addActionListener(this);
buttons.add(N3);
N3.addActionListener(this);
buttons.add(N12);
N12.addActionListener(this);
buttons.add(N0);
N0.addActionListener(this);
buttons.add(N13);
N13.addActionListener(this);
buttons.add(N15);
N15.addActionListener(this);
buttons.add(N14);
N14.addActionListener(this);
N16.addActionListener(this);
add("Center",buttons);
add("North",Enter);
add("South",N16);
addWindowListener(new WindowCloser());
pack();setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==N0) {
if(m.equals("0"))
Enter.setText("0");
else
Enter.setText(m+"0");
m=Enter.getText();
}
if(e.getSource()==N1&&(m.indexOf("+")==-1||m.indexOf("-")==-1||m.indexOf("*")==-1||m.indexOf("/")==-1)) {
if(m.equals("0"))
Enter.setText("1");
else
Enter.setText(m+"1");
m=Enter.getText();
}
if(e.getSource()==N2&&(m.indexOf("+")==-1||m.indexOf("-")==-1||m.indexOf("*")==-1||m.indexOf("/")==-1)) {
if(m.equals("0"))
Enter.setText("2");
else
Enter.setText(m+"2");
m=Enter.getText();
}
if(e.getSource()==N3&&(m.indexOf("+")==-1||m.indexOf("-")==-1||m.indexOf("*")==-1||m.indexOf("/")==-1)) {
//????m=Enter.getText();
if(m.equals("0"))
Enter.setText("3");
else
Enter.setText(m+"3");
m=Enter.getText();
}
if(e.getSource()==N4&&(m.indexOf("+")==-1||m.indexOf("-")==-1||m.indexOf("*")==-1||m.indexOf("/")==-1)) {