java语言写的计算器源代码附解析.doc
文本预览下载声明
//把代码改成Calc.java编译运行,完整版计算器,最下面是计算器界面
import java.awt.*;
import java.awt.event.*;
public class Calc extends WindowAdapter implements ActionListener, MouseListener
{
Color cMoveOut=new Color(240 ,240 ,240);
Color cMoveIn =new Color( 255,255,55);
//状态变量
boolean clicked=true;//判断是否单击了小数点
boolean clear=true;//判断是否单击了符号位
double previous;//记录第一个操作数
double next;//记录第二个操作数
String fuhao;//记录符号位
int first=1;//标记是否开始一次新的运算过程
Frame f;
Panel p1,p2;
TextField tf;
Font fnt;
Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b0;
Button bDiv,bSqrt,bMulti,bMinus,bPercent,bPlus,bReciprocal,bEqual,bDot,bNegative,bBack;
Button bPingFang , bDaoShu , bSin, bCos ,bTan;
Button bC;
GridLayout p2Layout;
public void display()
{
f=new Frame(计算器);
f.setSize(280,213);
f.setLocation(200,200);
f.setBackground(Color.LIGHT_GRAY);
f.setResizable(false);
p1=new Panel(new FlowLayout());
tf=new TextField(35);
tf.setText(0.);
tf.setEditable(false);
p1.add(tf);
f.add(p1,BorderLayout.NORTH);
p2Layout=new GridLayout(5,5,5,4);
p2=new Panel(p2Layout);
f.add(p2,BorderLayout.CENTER);
fnt=new Font(Serief,Font.BOLD,20);
b1=new Button(1);
b1.setFont(fnt);
b2=new Button(2);
b2.setFont(fnt);
b3=new Button(3);
b3.setFont(fnt);
b4=new Button(4);
b4.setFont(fnt);
b5=new Button(5);
b5.setFont(fnt);
b6=new Button(6);
b6.setFont(fnt);
b7=new Button(7);
b7.setFont(fnt);
b8=new Button(8);
b8.setFont(fnt);
b7.setFont(fnt);
b9=new Button(9);
b9.setFont(fnt);
b0=new Button(0);
b0.setFont(fnt);
b9.setFont(fnt);
bPingFang=new Button(^2);
bPingFang.setFont(fnt);
bDaoShu=new Button(1/X);
bDaoShu.setFont(fnt);
bSin=new Button(sin);
bSin.setFont(fnt);
bCos=new Button(cos);
bCos.setFont(fnt);
bTan=new Button(tan);
bTan.setFont(fnt);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListene
显示全部