版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
-.z.學(xué)號11710115**城建大學(xué)Java語言程序設(shè)計C實驗報告實驗5:計算器學(xué)生路江飛班級11卓越7班一、實驗?zāi)康?.掌握J(rèn)ava圖形組件和布局管理器的使用;2.掌握使用Java事件處理機(jī)制的使用;3.掌握圖形界面的各種控件的使用,如:標(biāo)簽、文本框、按鈕、復(fù)選框、列表框、窗框等。二、實驗要求1.采用布局管理器進(jìn)行界面的布局;2.學(xué)會對不同的事件用相應(yīng)的事件處理器;3.寫出實驗報告。要求記錄編譯和執(zhí)行Java程序當(dāng)中的系統(tǒng)錯誤信息提材示,并給出解決辦法。三、實驗容1.在隨堂練習(xí)的簡單計算器基礎(chǔ)上設(shè)計一個多功能計算器。包括復(fù)雜的功能:比如記憶功能,三角函數(shù),成方,對數(shù)等等。五、實驗結(jié)果文件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(){//運行程序時,點擊按鈕輸入公式,當(dāng)點擊等于號時顯示出計算結(jié)果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.顯示計算結(jié)果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);//按鈕'清零',監(jiān)聽到按鈕后清零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);//按鈕'退格',監(jiān)聽到按鈕后退格 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);//按鈕'*',監(jiān)聽到按鈕后顯示* 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',監(jiān)聽到按鈕后顯示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',監(jiān)聽到按鈕后顯示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',監(jiān)聽到按鈕后顯示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);//按鈕'-',監(jiān)聽到按鈕后顯示- 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',監(jiān)聽到按鈕后顯示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',監(jiān)聽到按鈕后顯示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',監(jiān)聽到按鈕后顯示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);//按鈕'+',監(jiān)聽到按鈕后顯示+ 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);//按鈕'=',點擊按鈕'=',將計算出結(jié)果********************************** 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){//除數(shù)等于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);//按鈕'.',監(jiān)聽到按鈕后顯示。. 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',監(jiān)聽到按鈕后顯示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);//按鈕'/',監(jiān)聽到按鈕后顯示/ 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',監(jiān)聽到按鈕后顯示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',監(jiān)聽到按鈕后顯示8 uttonbutton_14=newutton("8"); button_14.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2026福建南平市順昌縣第九屆人才南平校園行緊缺急需教師招聘14人參考考試試題及答案解析
- 2025年度葫蘆島市市直部分事業(yè)單位公開招聘高層次人才84人參考筆試題庫附答案解析
- 16.2.3 尺規(guī)作線段的垂直平分線 課件
- 2025浙江產(chǎn)權(quán)交易所有限公司第七期招聘1人備考筆試試題及答案解析
- 成都市人北實驗小學(xué)校2025-2026學(xué)年度校聘教師招聘模擬筆試試題及答案解析
- 2025河南鄭州鄭東新區(qū)春華學(xué)校教育集團(tuán)(商鼎校區(qū))招聘備考筆試題庫及答案解析
- 員工離職調(diào)查與分析報告模板
- 2026年春季開封尉氏縣外國語高級中學(xué)招聘教師23人備考筆試題庫及答案解析
- 2026廣東中山市教體系統(tǒng)第一期招聘事業(yè)單位人員117人參考考試試題及答案解析
- 2025赤峰市林西縣招聘14名專職消防員備考考試試題及答案解析
- 經(jīng)濟(jì)學(xué)論文題目經(jīng)濟(jì)學(xué)專業(yè)關(guān)鍵題目大全經(jīng)濟(jì)學(xué)開題報告參考文獻(xiàn)
- 重癥醫(yī)學(xué)科急性呼吸衰竭救治規(guī)范培訓(xùn)教程
- 衛(wèi)生部手術(shù)分級目錄(2025年1月修訂版)
- 鮮橙汁可行性研究報告
- 乘用車碰撞安全整車建模規(guī)范
- 中國煙草法務(wù)面試法律文書審核
- 粵省事食品安全管理員證考試題庫及答案解析
- 國美易卡借款合同范本
- 弱電機(jī)房施工方案
- 2025版腦損傷常見癥狀及護(hù)理策略
- GB/T 39693.4-2025硫化橡膠或熱塑性橡膠硬度的測定第4部分:用邵氏硬度計法(邵爾硬度)測定壓入硬度
評論
0/150
提交評論