1 / 15

CH 7 .Jav a GUI - AWT

CH 7 .Jav a GUI - AWT. 2012-2013- 2 卢晨 Roger. 课堂内容. 什么是 Java GUI 什么是 AWT Java GUI 组件和容器 Java GUI 事件处理. 2. Java GUI. Java GUI Java Graphics User Interface 图形化用户界面 提供用户与应用程序实现友好交互的桥梁 Java 实现技术 AWT Swing SWT. 4. AWT. AWT 抽象窗口工具包 Abstract Window Toolkit 支持开发小应用程序的简单用户界面

Télécharger la présentation

CH 7 .Jav a GUI - AWT

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CH7.Java GUI - AWT 2012-2013-2 卢晨 Roger

  2. 课堂内容 什么是Java GUI 什么是AWT Java GUI 组件和容器 Java GUI 事件处理 2

  3. Java GUI Java GUI Java Graphics User Interface图形化用户界面 提供用户与应用程序实现友好交互的桥梁 Java实现技术 AWT Swing SWT 4

  4. AWT AWT 抽象窗口工具包Abstract Window Toolkit 支持开发小应用程序的简单用户界面 GUI的各种元素由Java类实现,这些类一般在java.awt包及其子包中 相关软件包 java.awt包:提供基本的GUI组件、视觉控制和绘图工具API java.awt.event包:提供Java GUI事件处理API 5

  5. Java GUI三个部分内容 组件Component 容器Container 布局管理器LayoutManager 6

  6. AWT AWT核心类 component container 7

  7. Component & Container Component JavaGUI的最基本组成部分 Component及其子类的对象用来描述各种GUI元素,比如:按钮、标签等 一般的Component对象不能独立显示,必须放在某一个container对象中才可以显示 8

  8. Component & Container Container Container是Component的子类 通过使用add(.)方法向Container中添加其他Component对象 Container也可被当作Component对象添加到其他Container中 常用的Container Window :其对象表示可自由停泊的顶级窗口 Panel:其对象可作为容纳其他Component对象,但不能独立存在,必须被添加到其他Container(如Window或Applet)中 9

  9. Frame Frame带标题和边界的顶层窗口 Frame是Window的子类 常用构造方法 Frame() Frame(String s) 常用方法 GUI/TestFrame.java GUI/TestMultiFrame.java 10

  10. Panel Panel容纳组件的空间 Panel不能独立存在,必须被添加到其他容器中 可以采用与所在容器不能的布局管理器 常用构造方法 Panel()使用默认的FlowLayout类布局管理器初始化 Panel(LayoutManager layout)使用指定的布局管理器初始化 常用方法:继承自父类 setBounds() setSize() setLocation() setBackground() setLayout() GUI/TestPanel.java GUI/TestFrameWithPanel.java GUI/TestMultiPanel.java 11

  11. 练习 • 设计一个含有Panel的自定义的Frame类对象,形如: GUI/CenterPanel.java 12

  12. 布局管理器LayoutManager LayoutManager 管理Component在Container中的布局,不必直接设置Component的位置和大小 每个Container都有一个LayoutManager对象,当容器需要对某个组件进行定位或判断其大小时,就会调用其对应的布局管理器 可以调用Container的setLayout方法改变其布局管理器对象 13

  13. 布局管理器LayoutManager AWT提供了五种布局管理器 FlowLayout BorderLayout GridLayout CardLayout GridBagLayout 14

  14. FlowLayout FlowLayout流式布局 Panel和Applet的默认布局管理器类型 布局效果 Component在Container中按照加入次序逐行定位,行内从左到右,一行排满后换行 不改变组件尺寸,按组件原始尺寸显示 默认对齐方式为居中,也可在构造方法中设置不同的组件间距、行距和对齐方式 构造方法 public FlowLayout() public FlowLayout(int align) public FlowLayout(int align, int hgap, int vgap) 15

  15. FlowLayout 构造方法 GUI/TestFlowLayout.java GUI/TestFlowLayout2.java 16

More Related