图形用户界面编程.ppt
文本预览下载声明
.?图形用户接口 GUI 像WINDOWS一样通过鼠标移动图标下达命令的方式叫做GUI (Graphic User Interface)。 抽象窗口工具包(AWT)是一组Java类,此组Java类允许创建图形用户界面(GUI)。 AWT提供用于创建生动而高效的GUI的各种组件。 Java界面设计主要涉及AWT(Abstract Window Toolkit),Swing两大类库,Swing是AWT的扩展和功能的加强。 java.awt ---AWT components javax.swing-----Swing components AWT vs. Swing Components AWT Abstract Window Toolkit(抽象图形工具) 提供一系列的对象去创建图形用户界面(GUI) 在java.awt包里包括三种类型的类 组件: 可视化图形工具的基本类,包括容器 容器: 一种可以装载其他组件的特殊组件 布局管理器: 容器里用来定位(布置)用户界面组件的一种接口 java.awt 包中的类体系结构 AWT库使程序能够与桌面窗口系统原带的本机组件集成。 使用本机组件的优势在于,编程人员可以访问更多的本机功能,而且在某个特定的操作系统上,本机组件看起来与其余的应用程序是一致的。 但由于AWT支持多个不同的操作系统,AWT API局限于不同系统的共同功能。 Swing介绍 Java1.2引入称为Swing的新的GUI组件库。 Swing包括javax.swing包及其子包。 Swing有一个与平台无关的实现,而且具有一个艺术状态的属性集。 尽管Swing独立于AWT,但它是依照基本的 AWT类实现的。 Swing组件不会受任何操作系统的束缚。 Swing在不同的平台上表现一致,并且有能力提供本地窗口系统不支持的其它特性。 几乎所有拥有用户界面的基于Java的应用都是使用Swing GUI组件编写的。 Swing does’t replace the AWT component set,it extends it. Even when using Swing,we still rely on many classes from the AWT,particularly when it comes to GUI event handling. It is recommended that new GUI applications use Swing widgets and older programs convert to Swing. Swing组件以J开头,除了有与AWT类似的按钮(JButton)、标签(JLabel)、复选框(JCheckBox)、菜单(JMenu)等基本组件外,还增加了一个丰富的高层组件集合,如表格(JTable)、树(JTree)。 Swing 结构 Component类是所有AWT类的祖先,用来表示一个图形组件。 A container is a special type of component that is used to organize,manage,and present other components. But a component is not necessarily a container. Since a container can contain components,and a container is a component,then a container may contain other containers. Because all of the AWT and Swing components are descended from a common ancestor class, java.awt.Component, they all share a number of attributes and methods inherited from Component: Color(颜色): public void setBackground(Color?c) public void setForeground(Color?c) In Java,colors are implemented as objects belonging to the class java.awt.Color. The Color class defines a handful of static attributes,representing the following built-in colors: RED,BULE,GRE
显示全部