《Java高级程序设计》实验报告一.docx

上传人:b****1 文档编号:11006831 上传时间:2023-05-28 格式:DOCX 页数:25 大小:36.23KB
下载 相关 举报
《Java高级程序设计》实验报告一.docx_第1页
第1页 / 共25页
《Java高级程序设计》实验报告一.docx_第2页
第2页 / 共25页
《Java高级程序设计》实验报告一.docx_第3页
第3页 / 共25页
《Java高级程序设计》实验报告一.docx_第4页
第4页 / 共25页
《Java高级程序设计》实验报告一.docx_第5页
第5页 / 共25页
《Java高级程序设计》实验报告一.docx_第6页
第6页 / 共25页
《Java高级程序设计》实验报告一.docx_第7页
第7页 / 共25页
《Java高级程序设计》实验报告一.docx_第8页
第8页 / 共25页
《Java高级程序设计》实验报告一.docx_第9页
第9页 / 共25页
《Java高级程序设计》实验报告一.docx_第10页
第10页 / 共25页
《Java高级程序设计》实验报告一.docx_第11页
第11页 / 共25页
《Java高级程序设计》实验报告一.docx_第12页
第12页 / 共25页
《Java高级程序设计》实验报告一.docx_第13页
第13页 / 共25页
《Java高级程序设计》实验报告一.docx_第14页
第14页 / 共25页
《Java高级程序设计》实验报告一.docx_第15页
第15页 / 共25页
《Java高级程序设计》实验报告一.docx_第16页
第16页 / 共25页
《Java高级程序设计》实验报告一.docx_第17页
第17页 / 共25页
《Java高级程序设计》实验报告一.docx_第18页
第18页 / 共25页
《Java高级程序设计》实验报告一.docx_第19页
第19页 / 共25页
《Java高级程序设计》实验报告一.docx_第20页
第20页 / 共25页
亲,该文档总共25页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

《Java高级程序设计》实验报告一.docx

《《Java高级程序设计》实验报告一.docx》由会员分享,可在线阅读,更多相关《《Java高级程序设计》实验报告一.docx(25页珍藏版)》请在冰点文库上搜索。

《Java高级程序设计》实验报告一.docx

《Java高级程序设计》实验报告一

广东金融学院实验报告

课程名称:

Java高级程序设计

实验编号

及实验名称

实验一计算器

系别

计科系

姓名

学号

班级

实验地点

实验楼504

实验日期

2012-11-8

实验时数

6

指导老师

同组其他成员

成绩

一、实验目的

1、巩固java开发基础

2、学习Java图形界面开发技术

二、实验环境

1.使用软件:

WindowsXP、jdk1.6

2.实验设备:

微型计算机

三、实验内容及要求

参考书本87页程序Calculator.java,以此为基础扩展其功能,设计自己的计算器。

四、实验结果(附程序运行效果图)

importjava.awt.BorderLayout;

importjavax.swing.JPanel;

importjavax.swing.JFrame;

importjavax.swing.JTextField;

importjava.awt.Rectangle;

importjava.awt.GridBagLayout;

importjava.awt.GridLayout;

importjavax.swing.JButton;

importjava.awt.Point;

importjava.awt.event.KeyAdapter;

importjava.awt.event.KeyEvent;

importjava.awt.ComponentOrientation;

importjava.awt.Dimension;

publicclassCalculatorextendsJFrame{

privatestaticfinallongserialVersionUID=1L;

privateJPaneljContentPane=null;

privateJTextFieldtR=null;

privateJPanelp=null;

privateJButtonjButton=null;

privateJButtonjButton1=null;

privateJButtonjButton2=null;

privateJButtonjButton3=null;

privateJButtonjButton4=null;

privateJButtonjButton5=null;

privateJButtonjButton6=null;

privateJButtonjButton7=null;

privateJButtonjButton8=null;

privateJButtonjButton9=null;

privateJButtonjButton10=null;

privateJButtonjButton11=null;

privateJButtonjButton12=null;

privateJButtonjButton13=null;

privateJButtonjButton14=null;

privateJButtonjButton15=null;

privatedoubleresult=0;

privateStringlastCommand="=";//@jve:

decl-index=0:

privatebooleanstart=true;

privateJButtonjButton16=null;

privateJButtonjButton17=null;

privateJButtonjButton18=null;

privateJButtonjButton19=null;

/**

*Thisisthedefaultconstructor

*/

publicCalculator(){

super();

initialize();

}

privatevoidinitialize(){

this.setSize(290,190);

this.setResizable(false);

this.setLocation(newPoint(100,300));

this.setContentPane(getJContentPane());

this.setTitle("计算器");

}

/**

*ThismethodinitializesjContentPane

*

*@returnjavax.swing.JPanel

*/

privateJPanelgetJContentPane(){

if(jContentPane==null){

jContentPane=newJPanel();

jContentPane.setLayout(null);

jContentPane.add(getTR(),null);

jContentPane.add(getP(),null);

}

returnjContentPane;

}

/**

*ThismethodinitializestR

*

*@returnjavax.swing.JTextField

*/

privateJTextFieldgetTR(){

if(tR==null){

tR=newJTextField();

tR.setBounds(newRectangle(0,0,284,22));

tR.setComponentOrientation(ComponentOrientation.UNKNOWN);

tR.addKeyListener(newjava.awt.event.KeyAdapter(){

publicvoidkeyPressed(java.awt.event.KeyEvente){

charkey=e.getKeyChar();

if(key=='0'||key=='1'||key=='2'||key=='3'||key=='4'||key=='5'

||key=='6'||key=='7'||key=='8'||key=='9'||key=='.'){

if(start){

tR.setText("");

start=false;

}

tR.setText(tR.getText());

}

elseif(key=='+'||key=='-'||key=='*'||key=='/'||key=='='){

if(start){

if(key=='-'){

tR.setText(String.valueOf(key));

start=false;

}else

lastCommand=String.valueOf(key);

}else{

calculator(Double.parseDouble(tR.getText()));

lastCommand=String.valueOf(key);

start=true;

}

}

}

});

}

returntR;

}

/**

*Thismethodinitializesp

*

*@returnjavax.swing.JPanel

*/

privateJPanelgetP(){

if(p==null){

GridLayoutgridLayout=newGridLayout(5,4);

p=newJPanel();

p.setLayout(gridLayout);

p.setBounds(newRectangle(0,21,284,141));

p.add(getJButton16(),null);

p.add(getJButton17(),null);

p.add(getJButton18(),null);

p.add(getJButton19(),null);

p.add(getJButton2(),null);

p.add(getJButton9(),null);

p.add(getJButton13(),null);

p.add(getJButton15(),null);

p.add(getJButton14(),null);

p.add(getJButton11(),null);

p.add(getJButton10(),null);

p.add(getJButton7(),null);

p.add(getJButton6(),null);

p.add(getJButton1(),null);

p.add(getJButton(),null);

p.add(getJButton3(),null);

p.add(getJButton4(),null);

p.add(getJButton5(),null);

p.add(getJButton8(),null);

p.add(getJButton12(),null);

}

returnp;

}

/**

*ThismethodinitializesjButton

*

*@returnjavax.swing.JButton

*/

privateJButtongetJButton(){

if(jButton==null){

jButton=newJButton();

jButton.setText("6");

jButton.addActionListener(newjava.awt.event.ActionListener(){

publicvoidactionPerformed(java.awt.event.ActionEvente){

Stringinput=e.getActionCommand();

if(start){

tR.setText("");

start=false;

}

tR.setText(tR.getText()+input);

}

});

}

returnjButton;

}

/**

*ThismethodinitializesjButton1

*

*@returnjavax.swing.JButton

*/

privateJButtongetJButton1(){

if(jButton1==null){

jButton1=newJButton();

jButton1.setText("5");

jButton1.addActionListener(newjava.awt.event.ActionListener(){

publicvoidactionPerformed(java.awt.event.ActionEvente){

Stringinput=e.getActionCommand();

if(start){

tR.setText("");

start=false;

}

tR.setText(tR.getText()+input);

}

});

}

returnjButton1;

}

/**

*ThismethodinitializesjButton2

*

*@returnjavax.swing.JButton

*/

privateJButtongetJButton2(){

if(jButton2==null){

jButton2=newJButton();

jButton2.setText("+");

jButton2.addActionListener(newjava.awt.event.ActionListener(){

publicvoidactionPerformed(java.awt.event.ActionEvente){

Stringinput=e.getActionCommand();

if(start){

lastCommand=input;

}

else{

calculator(Double.parseDouble(tR.getText()));

lastCommand=input;

start=true;

tR.setText("");

}

}

}

);

}

returnjButton2;

}

/**

*ThismethodinitializesjButton3

*

*@returnjavax.swing.JButton

*/

privateJButtongetJButton3(){

if(jButton3==null){

jButton3=newJButton();

jButton3.setText(".");

jButton3.addActionListener(newjava.awt.event.ActionListener(){

publicvoidactionPerformed(java.awt.event.ActionEvente){

Stringinput=e.getActionCommand();

if(start){

tR.setText("");

start=false;

}

tR.setText(tR.getText()+input);

}

});

}

returnjButton3;

}

/**

*ThismethodinitializesjButton4

*

*@returnjavax.swing.JButton

*/

privateJButtongetJButton4(){

if(jButton4==null){

jButton4=newJButton();

jButton4.setText("1");

jButton4.addActionListener(newjava.awt.event.ActionListener(){

publicvoidactionPerformed(java.awt.event.ActionEvente){

Stringinput=e.getActionCommand();

if(start){

tR.setText("");

start=false;

}

tR.setText(tR.getText()+input);

}

});

}

returnjButton4;

}

/**

*ThismethodinitializesjButton5

*

*@returnjavax.swing.JButton

*/

privateJButtongetJButton5(){

if(jButton5==null){

jButton5=newJButton();

jButton5.setText("2");

jButton5.addActionListener(newjava.awt.event.ActionListener(){

publicvoidactionPerformed(java.awt.event.ActionEvente){

Stringinput=e.getActionCommand();

if(start){

tR.setText("");

start=false;

}

tR.setText(tR.getText()+input);

}

});

}

returnjButton5;

}

/**

*ThismethodinitializesjButton6

*

*@returnjavax.swing.JButton

*/

privateJButtongetJButton6(){

if(jButton6==null){

jButton6=newJButton();

jButton6.setText("4");

jButton6.addActionListener(newjava.awt.event.ActionListener(){

publicvoidactionPerformed(java.awt.event.ActionEvente){

Stringinput=e.getActionCommand();

if(start){

tR.setText("");

start=false;

}

tR.setText(tR.getText()+input);

}

});

}

returnjButton6;

}

/**

*ThismethodinitializesjButton7

*

*@returnjavax.swing.JButton

*/

privateJButtongetJButton7(){

if(jButton7==null){

jButton7=newJButton();

jButton7.setText("0");

jButton7.addActionListener(newjava.awt.event.ActionListener(){

publicvoidactionPerformed(java.awt.event.ActionEvente){

Stringinput=e.getActionCommand();

if(start){

tR.setText("");

start=false;

}

tR.setText(tR.getText()+input);

}

});

}

returnjButton7;

}

/**

*ThismethodinitializesjButton8

*

*@returnjavax.swing.JButton

*/

privateJButtongetJButton8(){

if(jButton8==null){

jButton8=newJButton();

jButton8.setText("3");

jButton8.addActionListener(newjava.awt.event.ActionListener(){

publicvoidactionPerformed(java.awt.event.ActionEvente){

Stringinput=e.getActionCommand();

if(start){

tR.setText("");

start=false;

}

tR.setText(tR.getText()+input);

}

});

}

returnjButton8;

}

/**

*ThismethodinitializesjButton9

*

*@returnjavax.swing.JButton

*/

privateJButtongetJButton9(){

if(jButton9==null){

jButton9=newJButton();

jButton9.setText("-");

jButton9.addActionListener(newjava.awt.event.ActionListener(){

publicvoidactionPerformed(java.awt.event.ActionEvente){

Stringinput=e.getActionCommand();

if(start){

tR.setText(input);

start=false;

}

else{

calculator(Double.parseDouble(tR.getText()));

lastCommand=input;

start=true;

tR.setText("");

}

}

});

}

returnjButton9;

}

/**

*ThismethodinitializesjButton10

*

*@returnjavax.swing.JBu

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

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2