Cup 5: Abstract Window Toolkit - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Cup 5: Abstract Window Toolkit

Description:

... all window systems. Functions are implemented by calling on native window system ... Window - free floating object that can be positioned on the screen ... – PowerPoint PPT presentation

Number of Views:125
Avg rating:3.0/5.0
Slides: 19
Provided by: timma87
Category:
Tags: abstract | cup | toolkit | window

less

Transcript and Presenter's Notes

Title: Cup 5: Abstract Window Toolkit


1
Cup 5 Abstract Window Toolkit
  • Special Topics Java

Dr. Tim Margush Department of Mathematics and
Computer Science The University of Akron
2
Abstract
  • Offers functions common to all window systems
  • Functions are implemented by calling on native
    window system functions
  • Adds an extra level of communication
  • Windows and components take on the
    characteristics of the host system

3
AWT Services
  • Standard GUI Components
  • Event handling system
  • Container class
  • Layout managers
  • Basic graphic operations

4
Component
  • Root class for most display oriented objects
  • Includes instance variables for location, size,
    color, font, etc.
  • There are two basic types of components
  • widgets (WIndows gaDGETS)
  • containers (this is an abstract class)

5
Component Attributes
  • Position and size
  • name
  • foreground and background colors
  • font
  • cursor
  • enabled
  • visible
  • valid

6
Container
  • Window - free floating object that can be
    positioned on the screen
  • Panel - a container that must be placed inside
    another container
  • Applet is derived from this class
  • Frame - subclass of window that adds a title
    string and menu capability
  • GUI application windows start here

7
A Self-Centered Window
  • Public class MeMyselfAndI
  • final private static int WW500, WH300
  • public static void main(String args)
  • Frame w new Frame(Me)
  • Dimension S w.getToolkit().getScreenSize()
  • w.setBounds((S.width-WW)/2, (S.height-WH)/2,WW,W
    H)
  • w.show()

8
An Eventful Window
  • public class ClosingWindow extends Frame
  • ClosingWindow(String s)
  • super(s)
  • enableEvents(AWTEvent.WINDOW_EVENT_MASK)
  • protected void processWindowEvent(WindowEvent e)
  • if (e.getID()WindowEvent.WINDOW_CLOSING)
  • dispose()
  • System.exit(0)
  • super.processWindowEvent(e)

9
Filling Containers
  • Container objects hold a list of Component
    objects
  • int countComponents()
  • Component getComponent(n),
  • Components are added at runtime
  • myContainer.add(aComponent)
  • A LayoutManager controls the positioning of the
    Components

10
Layout Manager
  • An object that controls size and placement of
    components added to a container
  • All containers have a default layout manager
  • You may choose a specific manager by calling the
    setLayout method
  • setLayout(layoutObject)

11
Flow Layout
  • aContainer.setLayout(new FlowLayout)
  • aContainer.add(new Button(x))
  • //add additional components
  • Components are displayed left to right,
    additional rows are used as needed.
  • Centered controls are the default but left and
    right alignment is possible
  • new FlowLayout(FlowLayout.LEFT)

12
Common Layout Managers
  • Flow
  • left to right, top to bottom
  • Border
  • north, south, east, west, center
  • Card
  • one on top of the other
  • Grid
  • rows and columns
  • GridBag
  • components occupy one or more grid cells

13
Combining Layout Managers
  • Each Container uses its own LayoutManager object
  • Inner nested containers are arranged by the outer
    container's LayoutManager
  • The contents of the inner containers are arranged
    by their respective LayoutManager

14
What's on the Menu
  • Menus are derived from MenuComponent
  • MenuBar - attaches to a frame
  • MenuItem - elements of a Menu
  • Menu - pulldown MenuItem
  • CheckboxMenuItem - checkable MenuItem
  • setMenuBar(MenuBar) - a Frame method to set the
    active menu bar

15
Menu Bar Items
  • The MenuBar's add method adds a Menu object to
    the menubar
  • You can also get, count, and remove Menus, and
    manipulate shortcuts
  • A Menu also has an add method to add a MenuItem
    to the Menu
  • sub menus are created by adding a Menu to a Menu

16
MenuItems
  • new MenuItem()
  • new MenuItem(String)
  • new menuItem(String, MenuShortcut)
  • Constructors to create a MenuItem object with
    indicated caption or label
  • MenuShortcut is another class that is used to
    associate a shortcut key with a MenuItem
  • Important methods for a MenuItem
  • setEnabled, setLabel, addActionListener

17
Menu
  • new Menu()
  • new Menu(String)
  • new Menu(String, boolean)
  • 2nd argument true means this is a "tear-off" menu
    (if supported)
  • Important methods
  • add(MenuItem or String)
  • addSeparator()

18
Checkbox Menu Items
  • new CheckboxMenuItem()
  • new CheckboxMenuItem(String)
  • new CheckboxMenuItem(String, boolean)
  • the boolean specifies the initial state
  • Important methods
  • addItemListener, getState, setState
Write a Comment
User Comments (0)
About PowerShow.com