Basic Graphical User Interface Components - PowerPoint PPT Presentation

About This Presentation
Title:

Basic Graphical User Interface Components

Description:

Panel - container (analog of parentheses) Object. CheckboxGroup. Component. FlowLayout ... Container. Choice. List. Checkbox. Label. TextField. Panel. Applet ... – PowerPoint PPT presentation

Number of Views:94
Avg rating:3.0/5.0
Slides: 19
Provided by: peterca3
Category:

less

Transcript and Presenter's Notes

Title: Basic Graphical User Interface Components


1
Basic Graphical User Interface Components
2
Component Descriptions
  • Label - uneditable text is displayed
  • Button - triggers an event when clicked
  • TextField - user keys in text displays text
  • Choice - drop-down list click selects item
  • Checkbox - boolean selected true
  • List - item list click selects item double
    click generates an action event
  • Panel - container (analog of parentheses)

3
Part of AWT class hierarchy
Object
CheckboxGroup
TextComponent
TextField
Component
Button
FlowLayout
Label
Object is in java.lang package
BorderLayout
Checkbox
GridLayout
List
Choice
Container
Panel
Applet
4
Label Class Some Methods
  • public Label()
  • Constructs empty Label
  • public Label(String s)
  • Constructs Label displaying String s
  • public Label(String s, int align)
  • Alignment values
  • Label.LEFT, Label.CENTER, Label.RIGHT

5
Label Class Some Methods ...
  • public String getText()
  • Returns Label text
  • public void setText(String s)
  • Sets Label text
  • public void setAlignment(int align)
  • Sets Label alignment
  • Label.LEFT, Label.CENTER, Label.RIGHT

6
Label Class Example
  • See Label entry on Lectures page

7
Part of AWT class hierarchy
Object
CheckboxGroup
TextComponent
TextField
Component
Button
FlowLayout
Label
BorderLayout
Checkbox
GridLayout
List
Choice
Container
Panel
Applet
8
Button Class Events
  • GUIs are event-driven
  • Activated when an event occurs
  • Events are initiated by the user
  • Press enter, a mouse button, or a key
  • To process an event, you must
  • register (aka delegate) an event listener
  • implement that event listener interface

9
Part of EventListener interface hierarchy
EventListener is in java.util package
EventListerner
Object
ActionListener
WindowListener
AdjustmentListener
TextListener
ComponentListener
MouseMotionListener
ContainerListener
MouseListener
FocusListener
KeyListener
ItemListener
10
Button Class Example
  • See Button entry on Lectures page
  • We defined the Button event handler as a separate
    class.
  • The event handler may be reused elsewhere
  • getActionCommand is a method of the ActionEvent
    class.

11
Part of AWT class hierarchy
Object
CheckboxGroup
TextComponent
TextField
Component
Button
FlowLayout
Label
BorderLayout
Checkbox
GridLayout
List
Choice
Container
Panel
Applet
12
TextField Class Methods
  • public TextField()
  • Constructs a TextField object
  • public TextField( int c )
  • Constructs a TextField with c columns
  • public TextField( String s )
  • Constructs a TextField displaying s.
  • public TextField( String s, int c )
  • Establishes both

13
TextField Class Methods ...
  • public void setEchoChar( char c )
  • Set display character when user enters text.
  • public void setEditable( boolean b )
  • Set whether or not TextField can be modified
  • true yes false no.
  • public String getText()
  • Return contents of TextField
  • public synchronized void setText( String s )
  • Set contents of TextField
  • There may be many ActionListeners, their set
    actions must be synchronized

14
TextField Class Example
  • See TextField entry on Lectures page

15
Part of AWT class hierarchy
Object
CheckboxGroup
TextComponent
TextField
Component
Button
FlowLayout
Label
BorderLayout
Checkbox
GridLayout
List
Choice
Container
Panel
Applet
16
Choice Class Methods
  • A Choice button is a drop-down list.
  • The Choice class implements the ItemSelectable
    interface
  • Methods include
  • public Choice()
  • Constructs a Choice drop-down list (empty)
  • public String getItem( int index )
  • Returns the item at index

17
Choice Class Methods ...
  • public synchronized void add( String s )
  • Adds an item to drop-down list.
  • public synchronized String getSelectedItem()
  • Returns the selected item.
  • public int getSelectedIndex()
  • Returns the index of the selected item.
  • public synchronized String insert(String s, int
    i)
  • Inserts a new item s at index i
  • public synchronized void remove( String s )
  • Removes the 1st occurrence of s from the list.

18
Choice Class Example
  • See Choice entry on Lectures page
Write a Comment
User Comments (0)
About PowerShow.com