java的计算器源代码_java计算器源代码

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

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)) {

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值