課件程序設(shè)計(jì)7 swing_第1頁
課件程序設(shè)計(jì)7 swing_第2頁
課件程序設(shè)計(jì)7 swing_第3頁
課件程序設(shè)計(jì)7 swing_第4頁
課件程序設(shè)計(jì)7 swing_第5頁
已閱讀5頁,還剩40頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

Swing用戶界Swing用戶界第十????Windows學(xué)習(xí)目學(xué)習(xí)目???能夠用WindowsBuilder創(chuàng)建We’veBeenProgramsWith1We’veBeenProgramsWith1£4.434ButTextButTextInterfacesAre5JavaCanJavaCanDo6BriefJava.awtBriefJava.awt(AbstractWindowsToolkit)and????Swing用戶界Swing用戶界第十????Windows三個(gè)頂三個(gè)頂層Swing容JFrame:每個(gè)JFrame對(duì)象實(shí)現(xiàn)單個(gè)主窗JApplet:每個(gè)JApplet對(duì)象在瀏覽器窗口實(shí)現(xiàn)一個(gè)applet的顯示大多數(shù)Swing組件的層次關(guān)大多數(shù)Swing組件的層次關(guān)java.lang.add(Component,ObjectSomeSomeComponentMorecomponentsComponentMorecomponentsareavailable Swing用戶界Swing用戶界第十????Windows布局管Java平布局管Java平臺(tái)提供5個(gè)常用的布局管理器:FlowLayout、在默認(rèn)情況下,每個(gè)容器有一個(gè)布局管理器。對(duì)象的默認(rèn)布局管理器是FlowLayout,而內(nèi)容調(diào)用容器的setLayout方法設(shè)置布局管理panel=newJPanel(panel.setLayout(newBorderLayout())You’realreadyusingaYou’realreadyusingamanager–It’sthedefaultforsomenewPutsasmanycomponentsaspossibleonarow,thenmovestothenextRowsarecreatedasneededtoaccommodateallofthecomponentsComponentsaredisplayedintheordertheyareaddedtothecontaineroooTheresult?Well,it有、eas有、easwes和納外空區(qū)域。如果東,西未用,center占滿全部將組將組件放在單行或單列中?將屏幕劃分成網(wǎng)格,將組件放在單元格中。允許組件占據(jù)一個(gè)或多個(gè)單元網(wǎng)格網(wǎng)格中的行和列可以有不同的寬度OtherLayout?MoresamplecodesonSwingareavailableat:OtherLayout?MoresamplecodesonSwingareavailableat: ??Swing用戶界Swing用戶界第十????布局管理WindowsBuilderEventsandAcomponentobjectmaygenerateaneventEventsandAcomponentobjectmaygenerateaneventobjectwillrespondtothe?Whentheevent?thecomponentcallstheappropriatemethodofthelistener,passinganobjectthatdescribestheeventE.g.aJbuttonwillcallactionPerformed(),passinginan?事件的相應(yīng)事件的相應(yīng)偵聽器接每個(gè)接口中聲明對(duì)這類事件的處理方通用類型的事件偵聽器在java.awt.event包中Swing組件特有的偵聽器在javax.swing.eventJava.awt.event包中事件偵Java.awt.event包中事件偵聽器接如何如何處理事處理事件必須完成的兩個(gè)關(guān)鍵任注冊(cè)事件偵聽 實(shí)現(xiàn)事件處理器(方法YoucanYoucansetupquiteImportthejava.awt.eventimportSpecifyinclassheaderthenameoflistenertobepublicclassExample_ActionListenerimplementsActionListenerWithinaddComponents()addalistenertoWriteanactionPerformed()methodIdentifiesthesourceoftheExecutesrelevantcodebasedontheJButtonb=newJButton("PressJButtonb=newJButton("PresspublicfinalclassWindowExampleRealButtonActionListener{……publicvoidlabel.setText("Countis"+}arg0)匿名類匿名類的使用(簡化版MoreonAnonymousClasses:事件適配器事件適配器因接口都是抽象的,當(dāng)通過實(shí)現(xiàn)Listener成事件處理時(shí),要同時(shí)實(shí)現(xiàn)接口中所有的方法.Listene(Adapter類)程序員可以擴(kuò)展適配器類,即用所需要的事處理重載那個(gè)方法的缺省實(shí)現(xiàn)一個(gè)事件適配器的子的象是相的事件聽型的象,例如MouseAdapte的子象是一個(gè)MouseListene?????適配器類和偵聽器接的實(shí)Example:事件適配適配器類和偵聽器接的實(shí)Example:事件適配器實(shí)現(xiàn)接鼠標(biāo)事鼠標(biāo)事件處鼠標(biāo)事件分為點(diǎn)擊和移動(dòng)事件,表示鼠標(biāo)事件的類publicvoidmouseDragged(MouseEventpublicvoidmouseMoved(MouseEvent鼠標(biāo)事鼠標(biāo)事件處鼠點(diǎn)的聽器接口是MouseListene,它有以下方法publicvoidmousePressed(MouseEventpublicvoidmouseReleaseed(MouseEventpublicvoidmouseEntered(MouseEventpublicvoidmouseExited(MouseEventpublicvoidmouseClicked(MouseEvent鍵盤事件處鍵盤事件處publickeyPressed(KeyEventkeyTyped(KeyEvente):該方法判public按下的鍵是否是一個(gè)特殊的動(dòng)作鍵(1)EventHandling(1)EventHandlingSwing用戶界Swing用戶界第十????WindowsQuestion–whynotQuestion–whynotuseCan’tICan’tIjustuseaE.g.theWindowBuilderadd-inforWindowsWindows例題索例例?例題索例例?例例10.2例10.3例10.4例10.5例10.6例10.7例?????????例例例???????MoreTutorialonMoreTutorialonswingcomponentsOtherinterestingGrid

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(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)論