Home : Course Map : Chapter 7 : Java : Supplements :
Swing Dialogs
JavaTech
Course Map
Chapter 7

Introduction
Event Overview
Event Processing
Button Events
  Demo 1
 Demo 2
Mouse Events
  Demo3

More Components
  Demo 4  Demo 5
  Demo 6  Demo 7

LayoutManagers-1
  Demo 8     Demo 9
  Demo 10  Demo 11
  Demo 12

LayoutManagers-2
  Demo 13  Demo 14
  Demo 15  Demo 16
  Demo 17

Inner Classes
Anonymous Class
Adapter Classes
  Demo 18  Demo 19
Frames & Menus
  Demo 20  Demo 21
Exercises

    Supplements
AWT Components
  Button
     Demo 1
  Canvas
     Demo 2
  AWT GUI Demo
     Demo 3
Swing Dialogs
JOptionPane Dialog
  Demo 1
JDialog
  Demo 2
UI Enhancement: P1
  Demo 1   Demo 2
  Demo 3

UI Enhancement: P2
  Demo 1
     About JavaTech
     Codes List
     Exercises
     Feedback
     References
     Resources
     Tips
     Topic Index
     Course Guide
     What's New

Dialogs are popup windows for communicating with the user for a specific purpose such as:

  • Warnings
  • Messages
  • Queries
  • Selection of a directory and/or files, typically for saving or opening a file.

A dialog window acts in two ways:

  • Modal - becomes the top window and will not release control to any other window until it is answered and closed.
  • Nonmodal - can become a secondary window while waiting to be answered and closed.
The Swing (javax.swing) framework provides several ways to create a dialog:
  • Create a subclass of JFrame and add dialog functionality yourself such as a window closing mechanism.

  • Subclass JDialog, which is a subclass of JFrame and provides various capabilities such as modal/non-modal behavior.

  • Use JOptionPane and its various methods such as showConfirmDialog() and showMessageDialog() to generate basic dialogs with icons, buttons, message text, and closing mechanism.

  • Use JFileChooser and JColorChooser for selecting files/directories and colors, resp.

Generally, the JOptionPane approach is the much easier one for basic dialogs and the two chooser classes are excellent for their tasks. Create a JDialog subclass when you need a more elaborate dialog with, for example, checkboxes or other components that provide the user with multiple options. JFrame subclasses should generally be reserved for more complex tasks that require a fully developed window.

In the following pages we provide demo programs to illustrate dialogs with JOptionPane

References & Web Resources

           Tech
Histogram UI
  Demo 1
Probablity Distrib.
  Demo 2 Demo 3
RejectionMethod
Histogram Stats
  Demo 4
Exercises

           Physics
Sim & Randomness
Custom Prob. Dist.
   Demo 1
Histogram Dist.
   Demo 2
Monte Carlo
  Demo 3
Exercises

  Part I Part II Part III
Java Core 1  2  3  4  5  6  7  8  9  10  11  12 13 14 15 16 17
18 19 20
21
22 23 24
Supplements

1  2  3  4  5  6  7  8  9  10  11  12

Tech 1  2  3  4  5  6  7  8  9  10  11  12
Physics 1  2  3  4  5  6  7  8  9  10  11  12

Java is a trademark of Sun Microsystems, Inc.