Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.

Similar presentations


Presentation on theme: "The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a."— Presentation transcript:

1 The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a robust event-handling model; graphics and imaging tools, including shape, color, and font classes; layout managers, for flexible window layouts that don't depend on a particular window size or screen resolution; data transfer classes, for cut-and-paste through the native platform clipboard.

2 AWT Hierarchy

3 AWT Overview Components –UI objects, such as buttons and labels Graphics Classes –Represents a “Drawing Context” –All drawing is done through this class Event Classes –Used to inform the program of user events (mouse, keyboard, etc) Image Class –Used to load, display and store images

4 Anatomy of an AWT Applet Subclasses Applet Creates Components to provide basic controls Using Containers and Layout Managers, it groups the Components User actions result in events –events are delivered to “event listeners”

5 AWT Overview Components –UI objects, such as buttons and labels Graphics Classes –Represents a “Drawing Context” –All drawing is done through this class Event Classes –Used to inform the program of user events (mouse, keyboard, etc) Image Class –Used to load, display and store images

6 Event Handling Events are generated by event sources One or more listeners can register to be notified about events of a particular kind from a particular source Event handlers can be instances of any class, as long as they implement an event listener interface

7 Laying out Components Layout managers control: –Where components appear –What sizes they are –How they react when they are resized The basic layout managers are: –BorderLayout (default for windows) –FlowLayout (default for panels) –GridLayout You can also use Absolute Positioning

8 BorderLayout It uses five areas to hold components: north, south, east, west, and center. All extra space is placed in the center area.

9 FlowLayout It simply lays out components from left to right, starting new rows if necessary

10 BorderLayout It uses five areas to hold components: north, south, east, west, and center. All extra space is placed in the center area.

11 FlowLayout It simply lays out components from left to right, starting new rows if necessary

12 CardLayout Use the CardLayout class when you have an area that can contain different components at different times

13 Using the Default Layout If you want to use the default layout manager, you don't have to do a thing. The constructor for each Container creates a layout manager instance and initializes the Container to use it. –All Panels (including Applets) default to FlowLayout –All Windows default to BorderLayout

14 Using a Non-Default Layout You need to create an instance of the desired layout manager class and tell the Container to use it. This code creates a CardLayout manager and sets it up as the layout manager for a Container: aContainer.setLayout(new CardLayout());

15 Using Graphics Overview “Graphics” objects are the key to all drawing They support primitive graphics... –Lines, Rectangles, Text … and Images They also store the “drawing context”: –Current drawing area –Current Drawing Color

16 Using Graphics: Drawing The AWT drawing system controls when and how programs can draw In response to a component’s repaint() method being called, the AWT invokes the Component's update() update() in turn (by default), calls the component’s paint() method.


Download ppt "The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a."

Similar presentations


Ads by Google