软件详细设计报告文档模板

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

软件详细设计报告文档模板1.引言1.1编写目的设计一个简单的计算器1.2背景A.简易计算器B.用java语言编写1.3参考资料参考《java程序设计》2.设计概述2.1任务和目标说明详细设计的任务及详细设计所要达到的目标。1.1.1需求概述支持GUI界面有计算结果的输出区域能够处理输入的0-9数字单击清除键清空输入历史和结果不支持优先级计算1.1.2运行环境概述Jdk1.63.系统详细设计3.1系统界面详细设计1.1.3外部界面设计importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;导包awtswing和eventpublicclassJCalculatorextendsJFrameimplementsActionListener{/***SerialVersionUID*/privatestaticfinallongserialVersionUID=-169068472193786457L;/***ThisclasshelpclosetheWindow.**/privateclassWindowCloserextendsWindowAdapter{publicvoidwindowClosing(WindowEventwe){System.exit(0);}}inti;//StringsforDigit&Operatorbuttons.privatefinalString[]str={7,8,9,/,4,5,6,*,1,2,3,-,.,0,=,+};//Buildbuttons.JButton[]buttons=newJButton[str.length];//Forcancelorreset.JButtonreset=newJButton(CE);//Buildthetextfieldtoshowtheresult.JTextFielddisplay=newJTextField(0);//界面的布局。publicJCalculator(){super(Calculator);//Addapanel.JPanelpanel1=newJPanel(newGridLayout(4,4));//panel1.setLayout(newGridLayout(4,4));for(i=0;istr.length;i++){buttons[i]=newJButton(str[i]);panel1.add(buttons[i]);}JPanelpanel2=newJPanel(newBorderLayout());//panel2.setLayout(newBorderLayout());panel2.add(Center,display);panel2.add(East,reset);//JPanelpanel3=newPanel();getContentPane().setLayout(newBorderLayout());getContentPane().add(North,panel2);getContentPane().add(Center,panel1);//Addactionlistenerforeachdigit&operatorbutton.for(i=0;istr.length;i++)buttons[i].addActionListener(this);//Addlistenerforresetbutton.reset.addActionListener(this);//Addlistenerfordisplaybutton.display.addActionListener(this);//TheclosebuttonX.addWindowListener(newWindowCloser());//Initializethewindowsize.setSize(800,800);//Showthewindow.//show();Usingshow()whileJDKversionisbelow1.5.setVisible(true);//Fitthecertainsize.pack();}//初始化界面publicvoidactionPerformed(ActionEvente){Objecttarget=e.getSource();Stringlabel=e.getActionCommand();if(target==reset)handleReset();elseif(0123456789..indexOf(label)0)handleNumber(label);elsehandleOperator(label);}//实现动作监听publicvoidhandleNumber(Stringkey){if(isFirstDigit)display.setText(key);elseif((key.equals(.))&&(display.getText().indexOf(.)0))display.setText(display.getText()+.);elseif(!key.equals(.))display.setText(display.getText()+key);isFirstDigit=false;}//把数字显示到文本框publicvoidhandleOperator(Stringkey){if(operator.equals(+))number+=Double.valueOf(display.getText());elseif(operator.equals(-))number-=Double.valueOf(display.getText());elseif(operator.equals(*))number*=Double.valueOf(display.getText());elseif(operator.equals(/))number/=Double.valueOf(display.getText());elseif(operator.equals(=))number=Double.valueOf(display.getText());display.setText(String.valueOf(number));operator=key;isFirstDigit=true;}//四则运算、publicstaticvoidmain(String[]args){newJCalculator();}}//主函数运行计算器的入口

1 / 5
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功