Title: AWT Abstract Window Toolkit
1AWT(Abstract Window Toolkit)
2Container Classes
3Container Classes
- Window - This class defines a window with no
title bar and no borders, not usually used by
itself. - Frame - Used as the basic Java application
window. - Has a title bar and provision for adding a menu.
- You can also add other components to it. You will
usually sub-class this class to create a window
class specific to your application. - You can then draw in this window if you want to.
4Container Classes
- Dialog - Used to define a dialog for inputting
data into a program. - FileDialog - Defines a dialog designed
specifically for selecting a file. - Panel - Used as a container for other
components. You cannot draw on a panel. - Applet - This is the base class for a Java
applet-a program designed to run embedded in a
web page. All applets have this class as a base.
You can draw in an Applet and add other
components.
5Container Layout Managers
6Default Layout Managers
- Window - BorderLayout
- Frame - BorderLayout
- Dialog - BorderLayout
- FileDialog - BorderLayout
- Panel - FlowLayout
- Applet - FlowLayout
7Container bounds and inset values
8Components that are not Containers
9Canvas Class
- Most of these classes define simple user
interface elements, but the Canvas class is a
little bit different. - You can use the Canvas class in two ways.
- Firstly, you can use it as a base class when you
define your own components. - Secondly you can draw on a Canvas object.
- The Canvas or Panel classes are usually extended
for drawing applications.
10Component abstract class
- java.awt.Component is an abstract class that
encapsulates the common functionality among AWT
components. - So much functionality is embedded in the
Component class that it provides a whopping 120
public methods.
11Component Attributes
- The Component class defines attributes which
record the following information about an object - position is stored as (x, y) coordinates in
relation to its container. - name of component stored as a String object
- size recorded as values for width height of
object - foreground background color that apply to the
object
12More Component Attributes
- The font used by the object when text is
displayed - cursor for the object-defines the appearance of
the cursor when it is over the object - Whether the object is enabled or not-if the
component is enabled it is active and can be
accessed by the user - Whether the object is visible on the screen or
not-if an object is not marked as visible it is
not drawn on the screen
13More Component Attributes
- Whether the object is 'valid' or not-
- if an object is not valid, layout of the entities
that make up the object has not been determined. - This is the case before an object is made
visible. - You can make a Container object invalid by
changing its contents. - It will then need to be validated
14java.awt.Component Properties Modifiable at
Runtime
15java.awt.Component Properties Modifiable at
Runtime cont.
16Size Position of Component
17Component Visual Characteristics
- The Look of a component is determined by two
things - representation of the component in the underlying
operating system that Java uses when the
component is displayed, - and whatever you draw on the component.
18Drawing on Component Objects
- You can draw on a Component object by
implementing its paint() method. - The paint() method is called automatically when
the component needs to be drawn, such as when
your program requests that the area the component
occupies should be redrawn, or the window
containing the component is resized.
19Drawing on Component Objects
- Your implementation of the paint() method must
include code to generate whatever you want drawn
within the Component object. - The component itself-the Button, Frame or
whatever, will be drawn for you. - You only need to override the paint() method for
any additional stuff that you want to draw on it.
20Component Visual Characteristics
21Creating Cursors
The Cursor class contains a range of final static
constants that specify standard cursor types
22Using Containers
- You can find out about the components in a
container object by using the following methods
defined in the Container class
23Adding Components to a Container
24Adding a Menu to a Window
- A menu bar and menu items within it, are not
components. - Classes in the java.awt package that enable you
to create a menu bar are based on the class
MenuComponent derived from Object.
25Adding a Menu to a Window
- You can operate on menu items by using the
following methods defined in the MenuItem class - Since the Menu class is a sub-class of MenuItem,
these methods also apply to Menu objects.
26Summary
- The package java.awt provides classes for
creating a graphical user interface (GUI) - A component is an object used to form part of the
GUI for a program. All components have the
class Component as a super-class - A container is a component that can contain other
components. A container object is created with a
class that is a sub-class of Container. The
classes Panel, Applet, Window, Frame, Dialog and
FileDialog are containers.
27Summary cont.
- The class Applet is the base class for an applet.
The Frame class is a base class for an
application window with a title bar, borders
and a menu - Arrangement of components in a container
controlled by a layout manager - A menu bar is represented by a MenuBar object.
Menu items can be objects of type Menu, of type
MenuItem, or of type CheckboxMenuItem
28Looks Like Times Up!