120 likes | 253 Views
Chapter 8. GUI in JAVA - The AWT. Goals AWT Components Layout Managers Frame Example Applet Example. Goals. First learn about the different objects that you can put on the screen Second address their associated events and provide event handling
E N D
Chapter 8 GUI in JAVA - The AWT • Goals • AWT Components • Layout Managers • Frame Example • Applet Example
Goals • First learn about the different objects that you can put on the screen • Second address their associated events and provide event handling • Almost all visual components are ultimately residing in a frame or panel • Frame - for application; Panel - for applet.
Goals • Understand event handling for AWT components • Understand the widgets available in Java • Understand how widgets must be attached to containers • Understand how “layout managers” support positioning
AWT - Abstract Windowing Toolkit • AWT can be used by both, applets and self-standing applications. • Is a standard component of the Java Development Kit (JDK) • Support for • mouse • keyboard • event handling
AWT Components • Button - pushbutton, • Label • Canvas - blank for drawing • Checkbox - togglebutton • Choice - Drop-down list, option menu • Component - root of the hierarchy (can be subclassed in 1.1) • FileDialog - supports browsing and selecting files • List - a list of selectable items
More Components • Scrollbar - slider for scrolling • TextArea - a multi-line area for displaying and editing text • TextField -a single-line text area • CheckboxMenuItem - toggle button in a menu • Menu - pulldown(or tear-off menu) • MenuBar - component to hold pulldown menues • MenuComponent - root of the menu component hierarchy • MenuItem - a menu button • PopupMenu - (1.1 only)
Container Components • Container - root of hierarchy (abstract - not displayable) • Dialog - suitable for dialog boxes • Frame - top-level window that can contain a menubar • Panel - empty toplevel container (parent of applet) • ScrollPane (1.1container that scrolls contents) • Window - no border. no menubar- parent of Frame and Dialog.
Layout Managers • Layout managers specify a policy for widget arrangement • BorderLayout - max of 5 components • NORTH,SOUTH,EAST,WEST,CENTER • default layout for Windows and its subclasses Frame and Dialog • FlowLayout - components are placed centered and left to right in a row • new row started when previous row is full • default layout for Panels and subclass Applet.
More Layout Managers • GridLayout - an n by m grid of components placed left to right, top to bottom. • GridBagLayout - components can take up adjacent grid positions through use of a GridBagConstraints object. • CardLayout - only one component is seen at a time with the ability to pull a component into view.
Application vs Applet • An applet is a subclass of panel. Thus it has a display area in which to draw graphics or display. • An application must create its own window done with a Frame object. • Application programming should register the Frame with a WindowListener to handle a closing event. • Only frames may contain menubars, but in 1.1 popup menues are not restricted to frames.
Swing • a collection of new components in a package called the Java Foundation Classes (JFC) • Support “tool tips” as pop-up labels that describe purpose of a component • Provide new high demand widgets such as • “tabbed panes” as sub panes each with a folder type tab • trees to display nested directory structures with a ‘+ ‘ to expand the tree • tables to display information returned from database access