帮助整合手册2javagui编程_第1页
帮助整合手册2javagui编程_第2页
帮助整合手册2javagui编程_第3页
帮助整合手册2javagui编程_第4页
帮助整合手册2javagui编程_第5页
已阅读5页,还剩3页未读 继续免费阅读

付费下载

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

第六讲、JavaGUI控件 JavaGUIOSJavaGUIAWT组件 响应不及微软的SDK丰富(因为有些OS平台无微软的Windows组件SunJava2SwingGUIJavaAppletApplication(1)AppletGUI FrameHTMLwidth、Height来指定。JavaAWT基本组件----它不能独立地显示出来并且在其内不能再包含其它的组件(Button、Checkbox、Choice、Canvas、Label、TextField、TextArea、List、ScrollbarAWT。容器组件(Container类):包含其它基本组件或子容器的组件,并由布局管理器统一决定其内的各个组件的摆放位置和大小(Frame窗框、Dialog 框、Panel面板、FileDialog文件 ①PanelApplet菜单条式菜单组件 Bar菜单条组件 级联菜单组件 Item菜单项组件 Component类:getBounds()andsetBounds(getBackground(),setBackground(),getForeground(),andsetForeground()getEnabled()andsetEnabled()getFont()andsetFont()getParent()getSize(),setSize(),getPreferredSize(),andsetPreferredSize()setVisible()

构建函数Label(Label(Stringtext),Label(Stringtextint构建函数Button(,Button(String方法:getLabel,setLabel(Stringintcolumns)方法:getColumns(),setColumns(intcolumns),setText(String构建函数TextAreaTextArea(introwsintcolumnsTextArea(Stringtext),TextArea(Stringtext,introws,intcolumns)TextArea(Stringtext,introws,intcolumns,int这里scrollbarsSCROLLBARS_BOTH,SCROLLBARS_VERTICAL_ONLY方法:getRows(getColumns(),setRows()setColumns(),insert(Stringstrintpositionappend(Stringstr) Checkbox(),Checkbox(Stringlabel),Checkbox(Stringlabel,booleanstate),Checkbox(Stringlabel,booleanstate,CheckboxGroupgroup),Checkbox(Stringlabel,CheckboxGroupgroup,boolean构建函数 List(),List(introws),List(introws,boolean构建函数 方法:addStringitem),addItem(Stringitem),selectintselect(String构建函数 Scrollbar(),Scrollbar(intScrollbar(intorientation,intvalue,intvisible,int构建函数 Canvas(),Canvas(GraphicsConfigurationadd()–usedtoaddacomponenttotheponent()and ponentAt()–obtainareferencetoacomponentinthegetInsets()–returninformationaboutacontainer’sremove()andremoveAll()–removecomponentsfromthegetLayout()andsetLayout()–getandsetthewayinwhichthecomponentsofthecontainerareorganized.validate()andvalidateTree()–causethecontainertobelaidoutand yed

方法:pack(,setSize(,show,toFront(andtoBack(,dispose(构建函数 Frame()andFrame(StringFrameFramef=new o,f.setSize(100, 100iswidth,120is // ythe 窗getFont()andsetFont(),getName()andsetName(),getParent(Bar:每一个Frame只可以有一 Bar用以容纳其他菜单组件。Frame有一 Bar,mb)方法:getLabelsetLabelsetShortcut(setShortcut(isEnabledandsetEnabled方法:addinsertremoveremoveAllgetItem(getItemCount 方法:getState(andsetState(JavaGUI 1init((JavaApplet而言)Frame的构造函数内(JavaApplication而言)创建出各个2、调用容器的add()分别将创建出的各个组件加入到Applet或Frame所在的容器中;然后 1init()Frame)4、再调用add()将各个子容器加入到Applet中或Frame的主窗框中;然后 Flowlayout(从上到下,从左到右依次摆放,每行均居中,它是Panel、Applet的缺省布局);Window、Dialog、Frame;;;setLayout()方法来指定所需的布局方式。setLayout(newFlowLayout());(setLayout(null)创建出菜单条BarFramesetBar()创建各个主级联菜单即(命令菜单ItemCheckboxItem类对象)及下一级子菜单(类的对象;可以为菜单项目加分隔线、加快捷键(Shortcut('快捷键字母'))等。将各个菜单项目(命令菜单及选择性菜单)添加到上一级对象中;然后各个菜单项目的器对象(对ItemActionListenerCheckboxItem则可以添加ItemListener接口。 Bar中

Applet中不能设计有菜单条菜

应该在某 , JavaGUI用户界面的:用户对程序的某一种功能性操作。Java中的主要有组件类componentEvent、状态发生变化时产生)和动作类(ActionEvent、TextEvent、AdjustmentEvent、ItemEvent共四类,它们均对应用户的某一种功能性操作动作;Java中的类都包含在JDKJava.awt.event包编程:用户编程定义每个特定发生时程序应做出何种响应,并且这些响应代码会在对应的发生时由系统自动调用。JDK1.1以上版本处理的机制:委托①源:产出②器:对组件所产生的作出具体响应的代吗,即产出与处理分别由两个不同类(它们可③处理机制:AWT组件自身不编程处理相应的,面是交由器(它可以是组件所在的Java器接口即可(处理模型④处理的包:java.awt.event包,它提供AWT所需的类和接口(ActionEvent类对应ActionListenerMouseEvent类对应MouseMotionListener接口和MouseListener接口、WindonEventWindonListenerXXXEvent类型的,那么处理该的接口XXXListenerEventObject各 类的说明 类的超最重要的方法--getSource(),返回产生 的对 类的超最重要的方法--getID(),返回某 的ID号 的ID是一个整数它指定 ,如最大化或最小化某一窗口:编程的基本原则处理的类代码要对某一类,并且给出该接口中定义的全部响应函数的功能实现(重写其函数体;然后在创建组件时该事件的::源通过对特定的进行,以指定该的器(响应者)函数:函数名由“add类型对应的器接口名称”组成;函数参数为器对象(实现响应的类的对象,如容器组件自身响应该,则器对象应用this。publicvoidadd<listenerType>(<listenerType>{

器对象(

类型

处理的类对象

Applet身实现多组的响应时,应实

现多 接 publicvoid }

对Applet自身可多 在事件处理类中在事件处理类中publicvoidactionPerFormed(ActionEvent{

{//利 }else }}publicvoidmouseDragged(MouseEvent

利 响应函数中对象获取 产生时的相关{//利 intint}

(数置空publicvoidmouseMove(MouseEvent{}} , 源对象 使用它的常见AWTButton,List,publicvoidactionPerformed(ActionEvent使用它的常见AWTObj.addAdjustmentListener(AdjustmentListener使用它的常见AWTpublicvoidcomponentResized(ComponentEvente)publicvoidcomponentMoved(ComponentEvente)publicvoidcomponentShown(ComponentEvente)publicvoidcomponentHidden(ComponentEvent使用它的常见AWTpublicvoidcomponentAdded(ContainerEventpublicvoidcomponentRemoved(ContainerEvent使用它的常见AWTCheckbox,Choice,publicvoiditemStateChanged(ItemEvent使用它的常见AWTpublicvoidfocusGained(FocusEventpublicvoidfocusLost(FocusEvent使用它的常见AWTpublicvoidkeyTyped(KeyEvente)publicvoidkeyPressed(KeyEvente)publicvoidkeyReleased(KeyEvent使用它的常见AWTpublicvoidmouseClicked(MouseEvente)publicvoidmousePressed(MouseEvente)publicvoidmouseReleased(MouseEvente)publicvoidmouseEntered(MouseEvente)publicvoidmouseExited(MouseEvent使用它的常见AWTpublicvoidmouseDragged(MouseEventpublicvoidmouseMoved(MouseEvent使用它的常见AWTTextField,使用它的常见AWTpublicvoidwindowOpened(WindowEvente)publicvoidwindowClosing(WindowEvente)publicvoidwindowClosed(WindowEvente)publicvoidwindowIconified(WindowEvente)publicvoidwindowDeiconified(WindowEvente)publicvoidwindowActivated(WindowEvente)publicvoidwindowDeactivated(WindowEvent①鼠 ②键 ③Frame主窗框 publicvoidwindowClosing(WindowEvent System.exit(0);//进程退出} Item对象添加 Itemone=new publicvoidactionPerformed(ActionEvent{}对Checkbox Item对象则可以添加ItemListener接口,在itemStat

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论