java课程实习报告Word格式文档下载.doc

上传人:b****1 文档编号:13161409 上传时间:2022-10-07 格式:DOC 页数:8 大小:50KB
下载 相关 举报
java课程实习报告Word格式文档下载.doc_第1页
第1页 / 共8页
java课程实习报告Word格式文档下载.doc_第2页
第2页 / 共8页
java课程实习报告Word格式文档下载.doc_第3页
第3页 / 共8页
java课程实习报告Word格式文档下载.doc_第4页
第4页 / 共8页
java课程实习报告Word格式文档下载.doc_第5页
第5页 / 共8页
点击查看更多>>
下载资源
资源描述

java课程实习报告Word格式文档下载.doc

《java课程实习报告Word格式文档下载.doc》由会员分享,可在线阅读,更多相关《java课程实习报告Word格式文档下载.doc(8页珍藏版)》请在冰豆网上搜索。

java课程实习报告Word格式文档下载.doc

1.3功能模块设计

计算器的模块设计图如下:

计算器界面

加运算

减运算

乘运算

除运算

归零

1.4工作原理

点击相应的数字键,即会在显示文档中显示该数字。

进行相应的运算,首先输入第一个计算数字,然后输入运算符,再输入第二个计算数字,点击“=”按钮即得计算结果。

同时,还有归零功能,点击该按钮,显示栏中即可归零。

2、具体实现

2.1类设计

类名:

jisuanqi

作用:

功能代码,窗口布局设定

publicclassCalculatorextendsWindowAdapter

{}

WindowAdapter实现了WindowListener的类,实现了WindowListener

frame.addWindowListener(newWindowAdapter(){});

———————————————————————————

WindowDestroyer

用于退出窗口动作

关键代码:

classcloseimplementsActionListener{

publicvoidactionPerformed(ActionEvente){

System.exit(0);

}

2.2模块及实现代码介绍

Framefm=newFrame("

简单计算器"

);

for(inti=0;

i<

=16;

i++){

b[i]=newButton(ss[i]);

}

=15;

p2.add(b[i]);

}//创建按钮并添加到P2

b[16].setBackground(Color.yellow);

txt=newTextField(15);

txt.setEditable(false);

b[i].addActionListener(newbuttonlistener());

……}

注:

此方法主要设置窗口、面板、各个按键。

对各个按键进行定义(定义好各按键该实现什么功能)、排布,将各个按键注册到监听器上。

txt.setText(txt.getText()+btn.getLabel());

if(btn.getLabel()=="

归零"

txt.setText("

"

该代码使每次进入时的文本都清空

classcloseimplementsActionListener{//退出

publicvoidactionPerformed(ActionEvente){

System.exit(0);

该方法实现了窗口的关闭

3、运行调试与分析讨论

调试运行4*5运算,运算过程如下所示:

1)命令提示符中运行计算器程序,如下图:

2)计算器界面显示,输入第一个运算值“4”,如下图:

3)输入运算符“*”,如下图:

4)输入第二个运算值“5”,如下图所示:

5)点击计算器按钮“=”,得出计算结果。

如下图:

4、设计体会与小结

附录:

(源程序)

importjava.awt.*;

importjava.awt.event.*;

publicclassjisuanqiextendsWindowAdapter{

Panelp1=newPanel();

Panelp2=newPanel();

Panelp3=newPanel();

TextFieldtxt;

privateButton[]b=newButton[17];

privateStringss[]={"

7"

"

8"

9"

+"

4"

5"

6"

-"

1"

2"

3"

*"

0"

="

/"

关闭"

};

staticdoublea;

staticStrings,str;

//定义变量创建对像

publicstaticvoidmain(Stringargs[]){

(newjisuanqi()).frame();

}

publicvoidframe(){

Framefm=newFrame("

for(inti=0;

b[i]=newButton(ss[i]);

}

p2.add(b[i]);

}//创建按钮并添加到P2

b[16].setBackground(Color.yellow);

txt=newTextField(15);

txt.setEditable(false);

b[i].addActionListener(newbuttonlistener());

//添加监听器

}

b[16].addActionListener(newclose());

fm.addWindowListener(this);

fm.setBackground(Color.red);

p1.setLayout(newBorderLayout());

p1.add(txt,"

North"

p2.setLayout(newGridLayout(4,4));

p3.setLayout(newBorderLayout());

p3.add(b[16]);

fm.add(p1,"

fm.add(p2,"

Center"

fm.add(p3,"

South"

fm.pack();

fm.setVisible(true);

//都是些窗中设置添加相关组件和监听器

publicvoidwindowClosing(WindowEvente){

System.exit(0);

//退出系统

classbuttonlistenerimplementsActionListener{

//编写监听器事件通过按键得出给果

publicvoidactionPerformed(ActionEvente){

Buttonbtn=(Button)e.getSource();

if(btn.getLabel()=="

){

jisuan();

str=String.valueOf(a);

txt.setText(str);

s="

;

}elseif(btn.getLabel()=="

txt.setText("

}else{

txt.setText(txt.getText()+btn.getLabel());

}

publicvoidjisuan(){//编写具体计算方法

if(s=="

a+=Double.parseDouble(txt.getText());

elseif(s=="

a-=Double.parseDouble(txt.getText());

a*=Double.parseDouble(txt.getText());

a/=Double.parseDouble(txt.getText());

else

a=Double.parseDouble(txt.getText());

7

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

当前位置:首页 > 考试认证 > IT认证

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

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