面向?qū)ο蟪绦蛟O(shè)計(jì)實(shí)驗(yàn)報(bào)告十一_第1頁(yè)
面向?qū)ο蟪绦蛟O(shè)計(jì)實(shí)驗(yàn)報(bào)告十一_第2頁(yè)
面向?qū)ο蟪绦蛟O(shè)計(jì)實(shí)驗(yàn)報(bào)告十一_第3頁(yè)
面向?qū)ο蟪绦蛟O(shè)計(jì)實(shí)驗(yàn)報(bào)告十一_第4頁(yè)
面向?qū)ο蟪绦蛟O(shè)計(jì)實(shí)驗(yàn)報(bào)告十一_第5頁(yè)
已閱讀5頁(yè),還剩7頁(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、-PAGE . z . I . . r . . 面向?qū)ο蟪绦蛟O(shè)計(jì)實(shí)驗(yàn)報(bào)告實(shí)驗(yàn)十一 繪制圖形【實(shí)驗(yàn)?zāi)康摹空莆帐褂脠D形類Graphics 畫(huà)出不同圖形的方法?!緦?shí)驗(yàn)容】選做一題1. 編寫(xiě)繪制圓形程序DrawOval.java。點(diǎn)擊確定按鈕時(shí),在畫(huà)布的指定位置畫(huà)圓。2. 編寫(xiě)移動(dòng)方塊程序MoveSquare.java。程序由二個(gè)類組成:窗體主類表現(xiàn)層負(fù)責(zé)控制,確定所有組件的位置,處理用戶對(duì)方塊的操作。畫(huà)布MoveCanvas類邏輯層負(fù)責(zé)繪圖,其paint負(fù)責(zé)繪制方塊,其方法moveUp(),moveDown(),moveLeft(),moveRight()分別響應(yīng)窗體主類actionPerforme

2、d ()方法的對(duì)應(yīng)的按鈕事件,再調(diào)用repaint方法來(lái)刷新圖像?!緦?shí)驗(yàn)報(bào)告】實(shí)習(xí)時(shí)間: 實(shí)習(xí)地點(diǎn): 實(shí)習(xí)機(jī)號(hào):具體實(shí)驗(yàn)容1. 編寫(xiě)繪制圓形程序DrawOval.java。點(diǎn)擊確定按鈕時(shí),在畫(huà)布的指定位置畫(huà)圓。運(yùn)行成功的程序?yàn)椋篿mport java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.*;import java*.swing.*;publicclassDrawOvale*tends JFrame implements ActionListener Ovalcanvas canva

3、s;JTe*tField in_R,in_*,in_Y;JButton btn;publicstaticvoid main(String args) / TODO Auto-generated method stubDrawOval DrawOval=new DrawOval();public DrawOval() super(畫(huà)布上繪制圓);setSize(600,300);setVisible(true);canvas=new Ovalcanvas();in_R=new JTe*tField(6);in_*=new JTe*tField(6);in_Y=new JTe*tField(6);

4、setLayout(new FlowLayout();add(new JLabel(輸入圓的位置坐標(biāo):);add(in_*);add(in_Y);add(new JLabel(輸入圓的半徑:);add(in_R);btn=new JButton(確定);btn.addActionListener(this);add(btn);add(canvas);validate();setDefaultCloseOperation(E*IT_ON_CLOSE);classOvalcanvase*tends Canvasint*,y,r;voidOvalcanvas() setSize(200,200);

5、setBackground(Color.cyan); publicvoid setOval(int*,inty,intr) this.*=*;this.y=y;this.r=r;publicvoid paint(Graphics g) g.drawOval(*, y, 2*r, 2*r);Overridepublicvoid actionPerformed(ActionEvent e) / TODO Auto-generated method stubint*,y,r;try *=Integer.parseInt(in_*.getTe*t(); y=Integer.parseInt(in_Y.

6、getTe*t(); r=Integer.parseInt(in_R.getTe*t();canvas.setOval(*,y,r);canvas.repaint();catch(NumberFormatE*ception ee) *=0;y=0;r=0;結(jié)果截圖:下面為具體實(shí)驗(yàn)過(guò)程:1運(yùn)行,出現(xiàn)錯(cuò)誤,主要是cannot be resolved to a type的錯(cuò)誤。WindowEvent cannot be resolved to a typeGraphics cannot be resolved to a typeConstant cannot be resolved to a var

7、iableConstant cannot be resolved to a variable換了一個(gè)程序,運(yùn)行,出現(xiàn)錯(cuò)誤:Multiple markers at this line- Synta* error on token (, delete this token- Synta* error on token ), delete this tokenMultiple markers at this line- Synta* error on token(s), misplaced construct(s)- Synta* error on token void, e*pected- Syn

8、ta* error, insert interface Identifier to complete InterfaceHeader(3)主窗體界面應(yīng)該調(diào)研setOval(int*,inty,intN)變成畫(huà)布類邏輯層。4按照云課堂PPT的程序,輸入,發(fā)現(xiàn)有如下錯(cuò)誤:Ovalcanvas cannot be resolved to a typeSynta* error on token Invalid Character, ; e*pectedJLable cannot be resolved to a typeSynta* error on token Invalid Character,

9、; e*pectedMultiple markers at this line- Ovalcanvas cannot be resolved to a type- Ovalcanvas cannot be resolved to a typeE*ception in thread main java.lang.Error: Unresolved compilation problem: at DrawOval.main(DrawOval.java:9)5第35行classOvalCanvase*tends Canvas應(yīng)該改為classOvalcanvase*tends Canvas,沒(méi)有注意

10、大小寫(xiě)。6第14行super(畫(huà)布上繪制圓);這里的;有問(wèn)題,忘了使用英文符號(hào)。7將以下程序: *=Integer.parseInt(jl1.getTe*t(); y=Integer.parseInt(jl2.getTe*t(); r=Integer.parseInt(jl3.getTe*t();改為:*=Integer.parseInt(in_*.getTe*t(); y=Integer.parseInt(in_Y.getTe*t(); r=Integer.parseInt(in_R.getTe*t();(8)經(jīng)過(guò)觀察,發(fā)現(xiàn)我之所以會(huì)出現(xiàn)JLable cannot be resolved t

11、o a type的錯(cuò)誤,是因?yàn)槲野袹Label寫(xiě)出了JLable.經(jīng)改善以上一系列程序錯(cuò)誤以后,我運(yùn)行程序,程序能運(yùn)行成功,但是當(dāng)我輸入圓的半徑及位置坐標(biāo)之后,點(diǎn)擊確定卻無(wú)法畫(huà)出一個(gè)與之相對(duì)應(yīng)的圓。明明程序是和教師PPT里的程序是一樣的,但就是畫(huà)不出圓來(lái)。在以上問(wèn)題的根底上,首先,我將第8行的代碼JLabel jl1,jl2;刪除。11其次,我將第22及23行的代碼jl1=new JLabel(輸入圓的位置坐標(biāo):);this.add(jl1);改為:add(new JLabel(輸入圓的位置坐標(biāo):);12最后,我將第25及26的代碼jl2=new JLabel(輸入圓的半徑:);this.ad

12、d(jl2);改為:add(new JLabel(輸入圓的半徑:);最后的最后,經(jīng)過(guò)一系列對(duì)該程序的摸索及改正,運(yùn)行成功,結(jié)果截圖為:實(shí)習(xí)小結(jié)1.實(shí)驗(yàn)一主要是卡在cannot be resolved to a type這里,比方說(shuō):Ellipse2D cannot be resolved to a type橢圓不能被解析為類型)等cannot be resolved to a type的類似錯(cuò)誤。這局部錯(cuò)誤主要是因?yàn)闆](méi)有注意英文字母的大小寫(xiě)以及中英式字符的使用而導(dǎo)致的,比方說(shuō)將JLabel寫(xiě)成了JLable則會(huì)出現(xiàn)JLable cannot be resolved to a type的錯(cuò)誤。在

13、以后的實(shí)驗(yàn)中還是要多注意字母的大小寫(xiě)這類小問(wèn)題,因?yàn)榇a總是英文和中文互用,很容易搞混。2.實(shí)驗(yàn)一還卡在以下錯(cuò)誤:OvalCanvas cannot be resolved to a type主要是因?yàn)镺valcanvas寫(xiě)成了OvalCanvas,字母大小寫(xiě)的問(wèn)題。Synta* error on token Invalid Character, ; e*pected。符號(hào);沒(méi)有用英文字符;的緣故。3.對(duì)于實(shí)驗(yàn)一,主要是要掌握主窗體界面應(yīng)該調(diào)研setOval(int*,inty,intN)變成畫(huà)布類邏輯層的知識(shí)點(diǎn)。難寫(xiě)的程序是以下局部:int*,y,r;try *=Integer.parseInt(in_*.getTe*t(); y=Integer.parseInt(in_Y.getTe*t(); r=Intege

溫馨提示

  • 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)論