版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
-.z.学号11710115**城建大学Java语言程序设计C实验报告实验5:计算器学生路江飞班级11卓越7班一、实验目的1.掌握Java图形组件和布局管理器的使用;2.掌握使用Java事件处理机制的使用;3.掌握图形界面的各种控件的使用,如:标签、文本框、按钮、复选框、列表框、窗框等。二、实验要求1.采用布局管理器进行界面的布局;2.学会对不同的事件用相应的事件处理器;3.写出实验报告。要求记录编译和执行Java程序当中的系统错误信息提材示,并给出解决办法。三、实验容1.在随堂练习的简单计算器基础上设计一个多功能计算器。包括复杂的功能:比如记忆功能,三角函数,成方,对数等等。五、实验结果文件1:packageputer;import;publicclasspuere*tendsJFrame{privateJPanelcontentPane;privateJTe*tFieldte*tField;privateJTe*tFieldte*tField_1;privateJTe*tFieldte*tField_2;privateJTe*tFieldte*tField_3;/** *Launchtheapplication. */publicstaticvoidmain(String[]args){ EventQueue.invokeLater(newRunnable(){publicvoidrun(){//运行程序时,点击按钮输入公式,当点击等于号时显示出计算结果try{ puerframe=newpuer(); frame.setVisible(true); Timetime=newTime(); time.setTime(frame.te*tField_3); Threadthread=newThread(time); thread.start(); }catch(E*ceptione){ e.printStackTrace(); } } }); }/** *Createtheframe.*/publicpuer(){ setTitle("\u8BA1\u7B97\u5668");setName("");finalStringBuffers=newStringBuffer(); setDefaultCloseOperation(JFrame.E*IT_ON_CLOSE); setBounds(100,100,412,448);contentPane=newJPanel();contentPane.setBorder(newEmptyBorder(5,5,5,5)); setContentPane(contentPane);contentPane.setLayout(null);te*tField=newJTe*tField();te*tField.setEnabled(false);te*tField.setLocale(Locale.UK);te*tField.setForeground(Color.PINK);te*tField.setTe*t("\u6B22\u8FCE\u4F7F\u7528\u8BA1\u7B97\u5668"te*tField.setBounds(10,20,368,30);contentPane.add(te*tField);te*tField.setColumns(10);te*tField_1=newJTe*tField();//文本框te*tField_1,显示公式te*tField_1.setBounds(10,102,368,30);contentPane.add(te*tField_1);te*tField_1.setColumns(10);te*tField_2=newJTe*tField();//文本框te*tField_2.显示计算结果te*tField_2.setBounds(10,142,368,30);contentPane.add(te*tField_2);te*tField_2.setColumns(10);te*tField_3=newJTe*tField();//文本框te*tField_3,显示电子表te*tField_3.setForeground(newColor(205,133,63));te*tField_3.setBounds(10,60,368,30);contentPane.add(te*tField_3);te*tField_3.setColumns(10);//按钮'清零',监听到按钮后清零uttonbtnC=newutton("\u6E05\u96F6");btnC.setForeground(Color.RED); btnC.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){te*tField_1.setTe*t("");te*tField_2.setTe*t(""); s.delete(0,s.length()); } }); btnC.setBounds(10,182,183,44);contentPane.add(btnC);//按钮'退格',监听到按钮后退格 uttonbutton_16=newutton("\u9000\u683C"); button_16.setForeground(Color.RED); button_16.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){ s.delete(s.length()-1,s.length()); Stringstr=s.toString();te*tField_1.setTe*t(str); } }); button_16.setBounds(193,182,185,44);contentPane.add(button_16);//按钮'*',监听到按钮后显示* uttonbutton_1=newutton("*"); button_1.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){ s.append('*'); Stringstr=s.toString();te*tField_1.setTe*t(str); } }); button_1.setBounds(285,271,93,44);contentPane.add(button_1);//按钮'6',监听到按钮后显示6 uttonbutton_2=newutton("6"); button_2.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){ s.append('6'); Stringstr=s.toString();te*tField_1.setTe*t(str); } }); button_2.setBounds(193,271,93,44);contentPane.add(button_2);//按钮'5',监听到按钮后显示5 uttonbutton_3=newutton("5"); button_3.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){ s.append('5'); Stringstr=s.toString();te*tField_1.setTe*t(str); } }); button_3.setBounds(100,271,93,44);contentPane.add(button_3);//按钮'4',监听到按钮后显示4 uttonbutton_4=newutton("4"); button_4.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){ s.append('4'); Stringstr=s.toString();te*tField_1.setTe*t(str); } }); button_4.setBounds(10,271,93,44);contentPane.add(button_4);//按钮'-',监听到按钮后显示- uttonbutton_5=newutton("-"); button_5.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){ s.append('-'); Stringstr=s.toString();te*tField_1.setTe*t(str); } }); button_5.setBounds(285,313,93,44);contentPane.add(button_5);//按钮'3',监听到按钮后显示3 uttonbutton_6=newutton("3"); button_6.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){ s.append('3'); Stringstr=s.toString();te*tField_1.setTe*t(str); } }); button_6.setBounds(193,313,93,44);contentPane.add(button_6);//按钮'2',监听到按钮后显示2 uttonbutton_7=newutton("2"); button_7.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){ s.append('2'); Stringstr=s.toString();te*tField_1.setTe*t(str); } }); button_7.setBounds(100,313,93,44);contentPane.add(button_7);//按钮'1',监听到按钮后显示1 uttonbutton_8=newutton("1"); button_8.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){ s.append('1'); Stringstr=s.toString();te*tField_1.setTe*t(str); } }); button_8.setBounds(10,313,93,44);contentPane.add(button_8);//按钮'+',监听到按钮后显示+ uttonbutton_9=newutton("+"); button_9.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){ s.append('+'); Stringstr=s.toString();te*tField_1.setTe*t(str); } }); button_9.setBounds(285,355,93,44);contentPane.add(button_9);//按钮'=',点击按钮'=',将计算出结果********************************** uttonbutton_10=newutton("="); button_10.setForeground(Color.RED); button_10.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){ Stringstr=s.toString(); Stringss=str; Stringinde*="[-]|[+]|[/]|[*]"; Stringnumber[]=str.split(inde*);intcount=number.length;doublenum[]=newdouble[count];for(inti=0;i<count;i++){ num[i]=Double.parseDouble(number[i]); }doubleresult=0;if(ss.contains("+")){ result=num[0];for(inti=1;i<count;i++){ result+=num[i]; } }if(ss.contains("-")){ result=num[0];for(inti=1;i<count;i++){ result-=num[i]; } }if(ss.contains("*")){ result=num[0];for(inti=1;i<count;i++){ result*=num[i]; } }if(ss.contains("/")){ result=num[0];for(inti=1;i<count;i++){if(num[i]==0){//除数等于0时,显示错误信息te*tField_2.setTe*t("出错");return; }else{ result/=num[i]; } } }//inti=(int)Math.round(result*100);//result=(double)i/100;te*tField_2.setTe*t(""+result); } }); button_10.setBounds(193,355,93,44);contentPane.add(button_10);//按钮'.',监听到按钮后显示。. uttonbutton_11=newutton("."); button_11.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){ s.append('.'); Stringstr=s.toString();te*tField_1.setTe*t(str); } }); button_11.setBounds(10,355,93,44);contentPane.add(button_11);//按钮'0',监听到按钮后显示0 uttonbutton_12=newutton("0"); button_12.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){ s.append('0'); Stringstr=s.toString();te*tField_1.setTe*t(str); } }); button_12.setBounds(100,355,93,44);contentPane.add(button_12);//按钮'/',监听到按钮后显示/ uttonbutton=newutton("/"); button.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){ s.append('/'); Stringstr=s.toString();te*tField_1.setTe*t(str); } }); button.setBounds(285,227,93,44);contentPane.add(button);//按钮'9',监听到按钮后显示9 uttonbutton_13=newutton("9"); button_13.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){ s.append('9'); Stringstr=s.toString();te*tField_1.setTe*t(str); } }); button_13.setBounds(193,227,93,44);contentPane.add(button_13);//按钮'8',监听到按钮后显示8 uttonbutton_14=newutton("8"); button_14.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年电网调度决策支持方法
- 慢性病营养治疗共识2026
- 护理科研中的实验设计
- 肿瘤晚期患者神经系统护理
- 康复护理与家庭康复
- 初中2025均衡膳食主题班会说课稿
- 第二课 精美的木雕说课稿2025学年高中美术人美版2019选择性必修3 雕塑-人美版2019
- 2026年四下语文母鸡说课稿
- 第8课 编辑幻灯片说课稿2025学年小学信息技术滇人版四年级第3册-滇人版
- 第17课 寻找快乐小妙方说课稿2025年小学心理健康一年级下册教科版
- 2025年能源控股集团所属辽宁铁法能源有限责任公司招聘笔试参考题库附带答案详解
- 2025-2030年中国核桃种植深加工行业竞争格局与前景发展策略分析报告
- 临床护理带教现状及改善
- 2025年高考英语完形填空+语法填空专练(原卷版+解析版)
- 室内设计cad培训
- 六年级数学总复习立体图形名师公开课获奖课件百校联赛一等奖课件
- 湖南高中物理学业水平考试公式及知识点总结学生
- 2022年湖南省普通高中学业水平合格考试-英语(含答案)
- 安全文明施工奖罚明细表
- HG/T 2782-2024 化工催化剂颗粒抗压碎力的测定(正式版)
- 2024年歌尔股份有限公司校园招聘考试试题汇编
评论
0/150
提交评论