Advanced GUI - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Advanced GUI

Description:

Always, ALWAYS, use lightweight (Swing or 'J') components when you can. ... component, the heavyweight component is always on top, regardless of the ... – PowerPoint PPT presentation

Number of Views:91
Avg rating:3.0/5.0
Slides: 14
Provided by: rob1125
Category:

less

Transcript and Presenter's Notes

Title: Advanced GUI


1
Advanced GUI
  • Robert Salkin
  • CSI 445 Advanced Java
  • Summer 2006, 6W3

2
What is a GUI?
  • GUI Graphical User Interface
  • A GUI allows the user to interact with the
    program in a more intuitive manner.
  • A GUI is usually preferred over a command-line
    interface.

3
Lightweight vs. Heavyweight
  • A heavyweight component is one that is associated
    with its own native screen resource (commonly
    known as a peer).
  • A lightweight component is one that "borrows" the
    screen resource of an ancestor (which means it
    has no native resource of its own -- so it's
    "lighter").
  • Lightweight components sit on top of heavyweight
    components.
  • Always, ALWAYS, use lightweight (Swing or J)
    components when you can.
  • All AWT components are heavyweight and all Swing
    components are lightweight, except for the
    top-level ones
  • JWindow
  • JFrame
  • JDialog
  • JApplet
  • The differences boil down to the following
  • A lightweight component can have transparent
    pixels a heavyweight is always opaque.
  • A lightweight component can appear to be
    non-rectangular because of its ability to set
    transparent areas a heavyweight can only be
    rectangular.
  • Mouse events on a lightweight component fall
    through to its parent mouse events on a
    heavyweight component do not fall through to its
    parent.
  • When a lightweight component overlaps a
    heavyweight component, the heavyweight component
    is always on top, regardless of the relative
    z-order  of the two components.
  • From http//java.sun.com/products/jfc/tsc/article
    s/mixing/

4
GUI Components Hierarchy
  • Object
  • Component
  • Container
  • JContainer
  • GUI components inherit from Component.
  • Container is a GUI component that can hold other
    components.
  • Notice that Container is a Component so
    Containers can be added to other Containers.
  • JComponent is the lightweight version of
    Container and is, therefore, the superclass of
    all lightweight Swing components.

5
Helpful Classes
  • JOptionPane
  • Static methods to create popup windows.
  • You can use
  • showInputDialog()
  • showMessageDialog()
  • showConfirmDialog()
  • showOptionDialog()
  • More universal, less easy.
  • JFrame
  • Used to create a program window.
  • JPanel
  • Container for Components.
  • BorderFactory
  • Static methods to create borders for JPanels.

6
Helpful Classes (contd)
  • JLabel
  • Text that cannot be modified by the user.
  • JTextField
  • Allows for data entry by the user.
  • JButton
  • Creates a button (and allows for click events).

7
Helpful Classes (contd)
  • JCheckBox
  • Gives the user an option to select (or not).
  • JComboBox
  • Makes a drop-down list.
  • JList
  • A list of options the user can select none, one,
    or more of.

8
Layout Managers
  • FlowLayout
  • Adds in order, from upper left to bottom right.
  • BorderLayout
  • Adds to one of 5 areas of the screen.
  • Default for JFrame.
  • GridLayout
  • Rows and column layout.
  • My favorite fast and easy.
  • GridBagLayout
  • Like GridLayout, but much more complex.
  • Uses Constraints to position Components.
  • BoxLayout
  • Allows for components to be arranged
    left-to-right or top-to-bottom.

9
Painting
  • To draw on the screen, implement your own
  • public void paintComponent(Graphics g)
  • To redraw the screen (by calling paintComponent
    indirectly), call
  • repaint()
  • Using the Graphics object, you draw many objects
    and set the background color.

10
More Advanced GUI Classes
  • JSlider
  • Allows the user to select from different values
    using a slider bar.
  • JMenuBar
  • Allows for menus, using
  • JMenuItem
  • JCheckBoxMenuItem
  • JRadioButtonMenuItem
  • JPopupMenu
  • Allows for context-sensitive menus.

11
More Advanced GUI Classes (contd)
  • JDesktopPane
  • Allows for JInternalFrame objects to act as
    windows within the parent window.
  • JTabbedPane
  • Allows for tabbed panes.

12
Look-and-Feel
  • A Pluggable Look-and-Feel allows the programmer
    to change the appearance, or look-and-feel, of
    the program.
  • Using UIManager and SwingUtilities, the
    programmer can switch between available modes.

13
Model-View-Controller (MVC)
  • For flexibility and portability, implement a GUI
    using MVC.
  • Model
  • Holds data and some algorithms.
  • View
  • The display of the underlying model, probably in
    some type of GUI.
  • Controller
  • Handles events, possibly modifying the Model and
    View.
  • The View and Controller are usually linked, since
    the Controller must be customized for each
    different View.
  • The Model is not dependent on the View or
    Controller.
  • This will not be covered in detail, but it was
    important to be mentioned.
Write a Comment
User Comments (0)
About PowerShow.com