《Java高級(jí)程序設(shè)計(jì)》實(shí)驗(yàn)報(bào)告一_第1頁(yè)
《Java高級(jí)程序設(shè)計(jì)》實(shí)驗(yàn)報(bào)告一_第2頁(yè)
《Java高級(jí)程序設(shè)計(jì)》實(shí)驗(yàn)報(bào)告一_第3頁(yè)
《Java高級(jí)程序設(shè)計(jì)》實(shí)驗(yàn)報(bào)告一_第4頁(yè)
《Java高級(jí)程序設(shè)計(jì)》實(shí)驗(yàn)報(bào)告一_第5頁(yè)
已閱讀5頁(yè),還剩15頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

第1頁(yè)共20頁(yè)廣東金融學(xué)院實(shí)驗(yàn)報(bào)告課程名稱:Java高級(jí)程序設(shè)計(jì)實(shí)驗(yàn)編號(hào)及實(shí)驗(yàn)名稱實(shí)驗(yàn)一計(jì)算器系別計(jì)科系姓名學(xué)號(hào)班級(jí)實(shí)驗(yàn)地點(diǎn)實(shí)驗(yàn)樓504實(shí)驗(yàn)日期20實(shí)驗(yàn)時(shí)數(shù)6指導(dǎo)老師同組其他成員無(wú)成績(jī)一、實(shí)驗(yàn)?zāi)康?、鞏固java開(kāi)發(fā)基礎(chǔ)2、學(xué)習(xí)Java圖形界面開(kāi)發(fā)技術(shù)二、實(shí)驗(yàn)環(huán)境1.使用軟件:WindowsXP、jdk1.62.實(shí)驗(yàn)設(shè)備:微型計(jì)算機(jī)三、實(shí)驗(yàn)內(nèi)容及要求參考書(shū)本87頁(yè)程序Calculator.java,以此為基礎(chǔ)擴(kuò)展其功能,設(shè)計(jì)自己的計(jì)算器。四、實(shí)驗(yàn)結(jié)果(附程序運(yùn)行效果圖)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("計(jì)算器"); } /** *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.JButton */ privateJButtongetJButton10(){ if(jButton10==null){ jButton10=newJButton(); jButton10.setText("9"); jButton10.addActionListener(newjava.awt.event.ActionListener(){ publicvoidactionPerformed(java.awt.event.ActionEvente){ Stringinput=e.getActionCommand(); if(start){ tR.setText(""); start=false; } tR.setText(tR.getText()+input); } }); } returnjButton10; } /** *ThismethodinitializesjButton11 * *@returnjavax.swing.JButton */ privateJButtongetJButton11(){ if(jButton11==null){ jButton11=newJButton(); jButton11.setText("8"); jButton11.addActionListener(newjava.awt.event.ActionListener(){ publicvoidactionPerformed(java.awt.event.ActionEvente){ Stringinput=e.getActionCommand(); if(start){ tR.setText(""); start=false; } tR.setText(tR.getText()+input); } }); } returnjButton11; } /** *ThismethodinitializesjButton12 * *@returnjavax.swing.JButton */ privateJButtongetJButton12(){ if(jButton12==null){ jButton12=newJButton(); jButton12.setText("="); jButton12.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(""+result); } } }); } returnjButton12; } /** *ThismethodinitializesjButton13 * *@returnjavax.swing.JButton */ privateJButtongetJButton13(){ if(jButton13==null){ jButton13=newJButton(); jButton13.setText("*"); jButton13.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(""); } } }); } returnjButton13; } /** *ThismethodinitializesjButton14 * *@returnjavax.swing.JButton */ privateJButtongetJButton14(){ if(jButton14==null){ jButton14=newJButton(); jButton14.setText("7"); jButton14.addActionListener(newjava.awt.event.ActionListener(){ publicvoidactionPerformed(java.awt.event.ActionEvente){ Stringinput=e.getActionCommand(); if(start){ tR.setText(""); start=false; } tR.setText(tR.getText()+input); } }); } returnjButton14; } /** *ThismethodinitializesjButton15 * *@returnjavax.swing.JButton */ privateJButtongetJButton15(){ if(jButton15==null){ jButton15=newJButton(); jButton15.setText("/"); jButton15.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(""); } } }); } returnjButton15; } publicvoidcalculator(doublex){ if(lastCommand.equals("+")) result+=x; elseif(lastCommand.equals("-")) result-=x; elseif(lastCommand.equals("*")) result*=x; elseif(lastCommand.equals("/")) result/=x; elseif(lastCommand.equals("squa")) result=Math.pow(Double.parseDouble(tR.getText()),2); elseif(lastCommand.equals("sqrt")) result=Math.sqrt(x); elseif(lastCommand.equals("=")) result=x; } /** *ThismethodinitializesjButton16 * *@returnjavax.swing.JButton */ privateJButtongetJButton16(){ if(jButton16==null){ jButton16=newJButton(); jButton16.setText("squa"); jButton16.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(""); } } }); } returnjButton16; } /** *ThismethodinitializesjButton17 * *@returnjavax.swing.JButton */ privateJButtongetJButton17(){ if(jButton17==null){ jButton17=newJButton(); jButton17.setText("sqrt"); jButton17.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(""); } } }); } returnjButton17; } /** *Thismeth

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論