科学计算器源代码Word文档格式.docx
- 文档编号:16246179
- 上传时间:2022-11-21
- 格式:DOCX
- 页数:18
- 大小:18.53KB
科学计算器源代码Word文档格式.docx
《科学计算器源代码Word文档格式.docx》由会员分享,可在线阅读,更多相关《科学计算器源代码Word文档格式.docx(18页珍藏版)》请在冰豆网上搜索。
2"
uttonbutton3=newutton("
3"
uttonbutton4=newutton("
+"
uttonbutton5=newutton("
c"
uttonbutton6=newutton("
4"
uttonbutton7=newutton("
5"
uttonbutton8=newutton("
6"
uttonbutton9=newutton("
-"
uttonbutton10=newutton("
退格"
uttonbutton11=newutton("
7"
uttonbutton12=newutton("
8"
uttonbutton13=newutton("
9"
uttonbutton14=newutton("
*"
uttonbutton15=newutton("
sin"
uttonbutton16=newutton("
uttonbutton17=newutton("
+/-"
uttonbutton18=newutton("
."
uttonbutton19=newutton("
/"
uttonbutton20=newutton("
="
uttonbutton21=newutton("
保存"
uttonbutton22=newutton("
复制"
uttonbutton23=newutton("
清除"
StringBufferS=newStringBuffer("
"
//t用来记录前一个运算符号是+-*/=中的哪一个
chart;
//count用来实现运算符号计数,a用来识别退格、正负号操作前一个操作是否是运算符号+-*/sin=
//intcount=0,a=0;
Double*1,*2=0d,result;
publicstaticvoidmain(Stringa[]){
calculatorthat=newcalculator();
that.go();
}
voidgo(){
leftpanel.setLayout(newBorderLayout());
leftpanel.add(fieldshow,BorderLayout.NORTH);
leftpanel.add(buttonpanel,BorderLayout.CENTER);
buttonpanel.setLayout(newGridLayout(4,5));
buttonpanel.add(button1);
buttonpanel.add(button2);
buttonpanel.add(button3);
buttonpanel.add(button4);
buttonpanel.add(button5);
buttonpanel.add(button6);
buttonpanel.add(button7);
buttonpanel.add(button8);
buttonpanel.add(button9);
buttonpanel.add(button10);
buttonpanel.add(button11);
buttonpanel.add(button12);
buttonpanel.add(button13);
buttonpanel.add(button14);
buttonpanel.add(button15);
buttonpanel.add(button16);
buttonpanel.add(button17);
buttonpanel.add(button18);
buttonpanel.add(button19);
buttonpanel.add(button20);
button1.addActionListener(this);
//事件监听
button2.addActionListener(this);
button3.addActionListener(this);
button4.addActionListener(this);
button5.addActionListener(this);
button6.addActionListener(this);
button7.addActionListener(this);
button8.addActionListener(this);
button9.addActionListener(this);
button10.addActionListener(this);
button11.addActionListener(this);
button12.addActionListener(this);
button13.addActionListener(this);
button14.addActionListener(this);
button15.addActionListener(this);
button16.addActionListener(this);
button17.addActionListener(this);
button18.addActionListener(this);
button19.addActionListener(this);
button20.addActionListener(this);
button21.addActionListener(this);
button22.addActionListener(this);
button23.addActionListener(this);
rightpanel.setLayout(newBorderLayout());
rightpanel.add(fieldcalculator,BorderLayout.NORTH);
rightpanel.add(area,BorderLayout.CENTER);
rightpanel.add(motionpanel,BorderLayout.SOUTH);
motionpanel.add(button21);
motionpanel.add(button22);
motionpanel.add(button23);
Containercon=frame.getContentPane();
frame.setLayout(newGridLayout(1,2));
con.add(leftpanel);
con.add(rightpanel);
frame.setBounds(200,200,600,300);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.E*IT_ON_CLOSE);
frame.addWindowListener(newWindowListener(){//关闭程序时弹出警告
publicvoidwindowClosing(WindowEvente){
intresult=JOptionPane.showConfirmDialog(frame,"
确实要关闭程序吗"
"
警告"
JOptionPane.OK_CANCEL_OPTION);
if(result==JOptionPane.OK_CANCEL_OPTION){
System.e*it(0);
}else{
}
}
publicvoidwindowOpened(WindowEvente){}
publicvoidwindowIconified(WindowEvente){}
publicvoidwindowDeiconified(WindowEvente){}
publicvoidwindowDeactivated(WindowEvente){}
publicvoidwindowClosed(WindowEvente){}
publicvoidwindowActivated(WindowEvente){}
});
publicvoidactionPerformed(ActionEvente){
//0123456789等按钮
if(e.getSource()==button1||e.getSource()==button2
||e.getSource()==button3||e.getSource()==button6
||e.getSource()==button7||e.getSource()==button8
||e.getSource()==button11||e.getSource()==button12
||e.getSource()==button13||e.getSource()==button16){
a=0;
if(count==0){
S.append(e.getActionmand());
fieldshow.setTe*t(S.toString());
*1=Double.parseDouble(fieldshow.getTe*t());
}elseif(count>
=1){
*2=Double.parseDouble(fieldshow.getTe*t());
}
//小数点的容错性
if(e.getSource()==button18)//单击"
按钮输入小数
{
if(fieldshow.getTe*t().trim().inde*Of("
)!
=-1)//判断字符串中是否已经包含了小数点
{
}else//如果没有小数点
if(fieldshow.getTe*t().trim().equals("
))//如果初时显示为0
{
S.setLength(0);
fieldshow.setTe*t((S.append("
+e.getActionmand()))
.toString());
}elseif(fieldshow.getTe*t().trim().equals("
))//如果初时显示为空则不做任何操作
fieldshow
.setTe*t(S.append(e.getActionmand()).toString());
//运算符号+-*/
if(e.getSource()==button4||e.getSource()==button9
||e.getSource()==button14||e.getSource()==button19){
count++;
a=1;
S.setLength(0);
if(e.getSource()==button4)//+法
switch(t){
case'
+'
:
result=*1+*2;
fieldshow.setTe*t(result.toString());
fieldcalculator.setTe*t(*1+"
+*2+"
+result);
area.append(*1+"
+result+"
\n"
break;
-'
result=*1-*2;
*'
result=*1**2;
/'
if(*2==0)
fieldshow.setTe*t("
除数不能为零"
else{
result=*1/*2;
fieldshow.setTe*t(result.toString());
fieldcalculator.setTe*t(*1+"
area.append(*1+"
}
='
default:
if(count<
}elseif(count>
=2){
*1=result;
t='
;
if(e.getSource()==button9)//-法
fieldcalculator.setTe*t(*1+"
default:
if(e.getSource()==button14)//*法
result=*1+*2;
if(e.getSource()==button19)///法
if(*2
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 科学 计算器 源代码