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

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

Swing用戶界Swing用戶界第十????Windows學習目學習目???能夠用WindowsBuilder創(chuàng)建We’veBeenProgramsWith1We’veBeenProgramsWith1£4.434ButTextButTextInterfacesAre5JavaCanJavaCanDo6BriefJava.awtBriefJava.awt(AbstractWindowsToolkit)and????Swing用戶界Swing用戶界第十????Windows三個頂三個頂層Swing容JFrame:每個JFrame對象實現(xiàn)單個主窗JApplet:每個JApplet對象在瀏覽器窗口實現(xiàn)一個applet的顯示大多數(shù)Swing組件的層次關大多數(shù)Swing組件的層次關java.lang.add(Component,ObjectSomeSomeComponentMorecomponentsComponentMorecomponentsareavailable Swing用戶界Swing用戶界第十????Windows布局管Java平布局管Java平臺提供5個常用的布局管理器:FlowLayout、在默認情況下,每個容器有一個布局管理器。對象的默認布局管理器是FlowLayout,而內容調用容器的setLayout方法設置布局管理panel=newJPanel(panel.setLayout(newBorderLayout())You’realreadyusingaYou’realreadyusingamanager–It’sthedefaultforsomenewPutsasmanycomponentsaspossibleonarow,thenmovestothenextRowsarecreatedasneededtoaccommodateallofthecomponentsComponentsaredisplayedintheordertheyareaddedtothecontaineroooTheresult?Well,it有、eas有、easwes和納外空區(qū)域。如果東,西未用,center占滿全部將組將組件放在單行或單列中?將屏幕劃分成網格,將組件放在單元格中。允許組件占據一個或多個單元網格網格中的行和列可以有不同的寬度OtherLayout?MoresamplecodesonSwingareavailableat:OtherLayout?MoresamplecodesonSwingareavailableat: ??Swing用戶界Swing用戶界第十????布局管理WindowsBuilderEventsandAcomponentobjectmaygenerateaneventEventsandAcomponentobjectmaygenerateaneventobjectwillrespondtothe?Whentheevent?thecomponentcallstheappropriatemethodofthelistener,passinganobjectthatdescribestheeventE.g.aJbuttonwillcallactionPerformed(),passinginan?事件的相應事件的相應偵聽器接每個接口中聲明對這類事件的處理方通用類型的事件偵聽器在java.awt.event包中Swing組件特有的偵聽器在javax.swing.eventJava.awt.event包中事件偵Java.awt.event包中事件偵聽器接如何如何處理事處理事件必須完成的兩個關鍵任注冊事件偵聽 實現(xiàn)事件處理器(方法YoucanYoucansetupquiteImportthejava.awt.eventimportSpecifyinclassheaderthenameoflistenertobepublicclassExample_ActionListenerimplementsActionListenerWithinaddComponents()addalistenertoWriteanactionPerformed()methodIdentifiesthesourceoftheExecutesrelevantcodebasedontheJButtonb=newJButton("PressJButtonb=newJButton("PresspublicfinalclassWindowExampleRealButtonActionListener{……publicvoidlabel.setText("Countis"+}arg0)匿名類匿名類的使用(簡化版MoreonAnonymousClasses:事件適配器事件適配器因接口都是抽象的,當通過實現(xiàn)Listener成事件處理時,要同時實現(xiàn)接口中所有的方法.Listene(Adapter類)程序員可以擴展適配器類,即用所需要的事處理重載那個方法的缺省實現(xiàn)一個事件適配器的子的象是相的事件聽型的象,例如MouseAdapte的子象是一個MouseListene?????適配器類和偵聽器接的實Example:事件適配適配器類和偵聽器接的實Example:事件適配器實現(xiàn)接鼠標事鼠標事件處鼠標事件分為點擊和移動事件,表示鼠標事件的類publicvoidmouseDragged(MouseEventpublicvoidmouseMoved(MouseEvent鼠標事鼠標事件處鼠點的聽器接口是MouseListene,它有以下方法publicvoidmousePressed(MouseEventpublicvoidmouseReleaseed(MouseEventpublicvoidmouseEntered(MouseEventpublicvoidmouseExited(MouseEventpublicvoidmouseClicked(MouseEvent鍵盤事件處鍵盤事件處publickeyPressed(KeyEventkeyTyped(KeyEvente):該方法判public按下的鍵是否是一個特殊的動作鍵(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等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論