计算器小程序javaWord下载.docx

上传人:b****3 文档编号:17883739 上传时间:2022-12-11 格式:DOCX 页数:5 大小:14.93KB
下载 相关 举报
计算器小程序javaWord下载.docx_第1页
第1页 / 共5页
计算器小程序javaWord下载.docx_第2页
第2页 / 共5页
计算器小程序javaWord下载.docx_第3页
第3页 / 共5页
计算器小程序javaWord下载.docx_第4页
第4页 / 共5页
计算器小程序javaWord下载.docx_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

计算器小程序javaWord下载.docx

《计算器小程序javaWord下载.docx》由会员分享,可在线阅读,更多相关《计算器小程序javaWord下载.docx(5页珍藏版)》请在冰豆网上搜索。

计算器小程序javaWord下载.docx

importjava.awt.event.WindowListener;

publicclassExam1_1extendsFrameimplementsActionListener,WindowListener{

TextFieldtext;

Stringa[];

Stringnames[]={"

<

-"

"

CE"

C"

cos"

sin"

7"

8"

9"

/"

sqrt"

4"

5"

6"

×

"

%"

1"

2"

3"

1/x"

0"

+/-"

."

+"

="

};

Buttonbut[]=newButton[names.length];

Stringss=newString();

Strings=newString();

StringBuffersb=newStringBuffer();

Exam1_1(){

super("

计算器"

);

inti;

text=newTextField();

Panelp=newPanel();

p.setLayout(newGridLayout(5,5,5,5));

for(i=0;

i<

names.length;

i++){

but[i]=newButton(names[i]);

but[i].addActionListener(this);

but[i].setForeground(Color.red);

p.add(but[i]);

}

setSize(300,300);

Fontf=newFont("

楷体"

Font.BOLD,25);

setFont(f);

setLayout(newBorderLayout(10,10));

add(text,BorderLayout.NORTH);

add(p,BorderLayout.CENTER);

setVisible(true);

addWindowListener(this);

}

publicvoidactionPerformed(ActionEventarg0){

ss=arg0.getActionCommand();

if(ss.equals("

)){s=sb.substring(0,s.length()-1);

text.setText(s);

}

)){sb=newStringBuffer();

s=sb.toString();

text.setText("

"

)){floatf=Float.valueOf(text.getText()).floatValue();

doublem=Math.cos(f);

sb=newStringBuffer();

;

text.setText(String.valueOf(m));

doublem=Math.sin(f);

)){sb.append("

doublem=Math.sqrt(f);

doublem=1/f;

doublem=-f;

)){

if(s.indexOf("

)>

=1){

a=s.split("

2);

doublei1=Double.valueOf(a[0]).doubleValue();

doublei2=Double.valueOf(a[1]).doubleValue();

doublei3=i1+i2;

text.setText(String.valueOf(i3));

}

elseif(s.indexOf("

a=s.split("

doublej1=Double.valueOf(a[0]).doubleValue();

doublej2=Double.valueOf(a[1]).doubleValue();

doublej3=j1-j2;

text.setText(String.valueOf(j3));

doublei3=i1*i2;

doublei3=i1/i2;

doublei3=i1%i2;

publicvoidwindowActivated(WindowEventarg0){

//TODOAuto-generatedmethodstub

publicvoidwindowClosed(WindowEventarg0){

publicvoidwindowClosing(WindowEventarg0){

Windoww=(Window)arg0.getSource();

w.setVisible(false);

w.dispose();

publicvoidwindowDeactivated(WindowEventarg0){

publicvoidwindowDeiconified(WindowEventarg0){

publicvoidwindowIconified(WindowEventarg0){

publicvoidwindowOpened(WindowEventarg0){

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 研究生入学考试

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1