16
(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.

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

Embed Size (px)

Citation preview

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

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.

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

AWT Hierarchy

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

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

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

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”

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

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

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

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

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

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

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

BorderLayout

• It uses five areas to hold components: north, south, east, west, and center.

• All extra space is placed in the center area.

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

FlowLayout

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

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

BorderLayout

• It uses five areas to hold components: north, south, east, west, and center.

• All extra space is placed in the center area.

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

FlowLayout

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

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

CardLayout

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

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

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

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

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());

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

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

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

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.