欢迎来到天天文库
浏览记录
ID:22898819
大小:113.00 KB
页数:6页
时间:2018-11-01
《《java简易计数器》word版》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、packagemy_calculator;publicclassMainclass{publicstaticvoidmain(String[]args){MyFramemf=newMyFrame("Calculator");}}====================================================packagemy_calculator;importjava.awt.*;importjava.awt.event.*;importjava.math.*;publicclassMyFrameext
2、endsFrame{Labellab;ButtonPanelbp;intflag;doubleresult;booleanpt;booleanequal;publicMyFrame(Stringarg0)throwsHeadlessException{super(arg0);Buttonbt=newButton("CE");pt=false;equal=true;result=0.0d;flag=0;lab=newLabel("0",Label.RIGHT);bp=newButtonPanel();setLayout(newB
3、orderLayout());add(lab,BorderLayout.NORTH);add(bp,BorderLayout.CENTER);add(bt,BorderLayout.SOUTH);setLocation(200,200);setSize(300,300);setVisible(true);addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEventarg0){System.exit(0);}});bt.addActionList
4、ener(newActionListener(){publicvoidactionPerformed(ActionEventarg0){result=0.0d;lab.setText("0");}});bp.bt[0].addActionListener(newActionListener(){publicvoidactionPerformed(ActionEventarg0){if(equal==false){lab.setText("7");equal=true;}elseif(pt
5、
6、Double.parseDouble
7、(lab.getText())!=0)lab.setText((newStringBuilder(String.valueOf(lab.getText()))).append("7").toString());elselab.setText("7");}});bp.bt[1].addActionListener(newActionListener(){publicvoidactionPerformed(ActionEventarg0){if(equal==false){lab.setText("8");equal=true;}
8、elseif(pt
9、
10、Double.parseDouble(lab.getText())!=0)lab.setText((newStringBuilder(String.valueOf(lab.getText()))).append("8").toString());elselab.setText("8");}});bp.bt[2].addActionListener(newActionListener(){publicvoidactionPerformed(ActionEventarg0){if(equal==false){
11、lab.setText("9");equal=true;}elseif(pt
12、
13、Double.parseDouble(lab.getText())!=0)lab.setText((newStringBuilder(String.valueOf(lab.getText()))).append("9").toString());elselab.setText("9");}});bp.bt[3].addActionListener(newActionListener(){publicvoidactionPerformed(Actio
14、nEventarg0){flag=1;pt=false;result=Double.parseDouble(lab.getText());lab.setText("0");}});bp.bt[4].addActionListener(newActionListener(){p
此文档下载收益归作者所有