- Forward


Windowing
An Introduction with Examples in Java


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Windows
Back SMYC Forward
  • Defined:
    • A generic top-level container (i.e., isn't inside another container) of GUI components
  • Uses:
    • Messages, request input, visually divide an application...
  • Modal vs. Modeless:
    • Blocking vs. Non-blocking
Windows in Java
Back SMYC Forward

Class Hierarchy

images/java-window-hierarchy.gif
Windows in Java (cont.)
Back SMYC Forward
  • Window java.awt.Window
    • show()
    • hide()
    • dispose()
  • Frame java.awt.Frame
    • getTitle(), setTitle()
    • getIconImage(), setIconImage()
    • isResizable(), setResizable()
    • isVisible(), setVisible()
Windows in Java (cont.)
Back SMYC Forward

A Simple Example

JFrame frame = new JFrame("Amazing!"); frame.setSize(400, 400); frame.setVisible(true);
Menus
Back SMYC Forward

Using Something Like the Composite Pattern

images/menu-menuitem.gif

It would be better if there were a JMenuComponent interface that both the JMenuItem and the JMenu implemented (realizations of which could be added to a JMenu).

Menus (cont.)
Back SMYC Forward

An Example

javaexamples/layout/MenuBarDriver.java
 
Dialog Boxes
Back SMYC Forward
  • Standard Types:
    • Message Dialog
    • Option Dialog
    • Input Dialog
    • File Dialog
    • Color Dialog
  • Custom:
    • Use a modal window
    • Sometimes return information and sometimes require a callback
Dialog Boxes (cont.)
Back SMYC Forward

An Example Message Dialog

javaexamples/usinggui/MessageDialogDriver.java
 
Dialog Boxes (cont.)
Back SMYC Forward

An Example Option Dialog

javaexamples/usinggui/OptionDialogDriver.java
 
Dialog Boxes (cont.)
Back SMYC Forward

An Example Input Dialog

javaexamples/usinggui/InputDialogDriver.java
 
Dialog Boxes (cont.)
Back SMYC Forward

An Example File Dialog

javaexamples/usinggui/FileDialogDriver.java
 
Dialog Boxes (cont.)
Back SMYC Forward

An Example Color Dialog

javaexamples/usinggui/ColorDialogDriver.java
 
There's Always More to Learn
Back -