AWT Abstract Window Toolkit - PowerPoint PPT Presentation

1 / 28
About This Presentation
Title:

AWT Abstract Window Toolkit

Description:

cursor for the object-defines the appearance of the cursor when ... Creating Cursors. The Cursor class contains a range of final static constants that specify ... – PowerPoint PPT presentation

Number of Views:407
Avg rating:3.0/5.0
Slides: 29
Provided by: gar59
Category:

less

Transcript and Presenter's Notes

Title: AWT Abstract Window Toolkit


1
AWT(Abstract Window Toolkit)
2
Container Classes
3
Container 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.

4
Container 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.

5
Container Layout Managers
6
Default Layout Managers
  • Window - BorderLayout
  • Frame - BorderLayout
  • Dialog - BorderLayout
  • FileDialog - BorderLayout
  • Panel - FlowLayout
  • Applet - FlowLayout

7
Container bounds and inset values
8
Components that are not Containers
9
Canvas 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.

10
Component 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.

11
Component 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

12
More 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

13
More 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

14
java.awt.Component Properties Modifiable at
Runtime
15
java.awt.Component Properties Modifiable at
Runtime cont.
16
Size Position of Component
17
Component 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.

18
Drawing 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.

19
Drawing 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.

20
Component Visual Characteristics
21
Creating Cursors
The Cursor class contains a range of final static
constants that specify standard cursor types
22
Using Containers
  • You can find out about the components in a
    container object by using the following methods
    defined in the Container class

23
Adding Components to a Container
24
Adding 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.

25
Adding 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.

26
Summary
  • 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.

27
Summary 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

28
Looks Like Times Up!
  • What so soon?
Write a Comment
User Comments (0)
About PowerShow.com