byucc.jhdl.util.gui
Class MessageBox

java.lang.Object
  extended bybyucc.jhdl.util.gui.MessageBox
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener, java.awt.event.KeyListener, java.lang.Runnable, java.awt.event.WindowListener

public class MessageBox
extends java.lang.Object
implements java.lang.Runnable, java.awt.event.ActionListener, java.awt.event.WindowListener, java.awt.event.KeyListener

Provides a reusable window that presents a message and choice buttons to the user. A modal dialog is used. Since a thread is used to set the dialog to visible, when the client calls ask() it will not block. The client may implement ActionListener, which has: public void actionPerformed(ActionEvent evt) if user response notification is desired.

Author:
Jack Harich

Constructor Summary
MessageBox()
          This constructor is used for no listener, such as for a simple okay dialog.
MessageBox(java.awt.event.ActionListener listener)
          This convenience constructor is used to delare the listener that will be notified when a button is clicked.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent evt)
           
 void addChoice(java.lang.String label)
          A convenience method that assumes the command is the same as the label.
 void addChoice(java.lang.String label, java.lang.String command)
          The @param label will be used for the button and the
 void ask(java.lang.String message)
          One of the "ask" methods must be the last call when using a MessageBox.
 void askOkay(java.lang.String message)
          Same as ask(String message) except adds an "Okay" button.
 void askYesNo(java.lang.String message)
          Same as ask(String message) except adds "Yes" and "No" buttons.
 void keyPressed(java.awt.event.KeyEvent evt)
           
 void keyReleased(java.awt.event.KeyEvent evt)
           
 void keyTyped(java.awt.event.KeyEvent evt)
           
static void main(java.lang.String[] args)
           
 void run()
          This prevents the caller from blocking on ask(), which if this class is used on an awt event thread would cause a deadlock.
 void setActionListener(java.awt.event.ActionListener listener)
          This set the listener to be notified of button clicks and WindowClosing events.
 void setCloseWindowCommand(java.lang.String command)
          Sets the ActionCommand used in the ActionEvent when the user attempts to close the window.
 void setFrame(java.awt.Frame frame)
          If a Frame is provided then it is used to instantiate the modal Dialog.
 void setTitle(java.lang.String title)
           
 void useImageCanvas(java.awt.Canvas imageCanvas)
          This is handy for providing a small image that will be displayed to the left of the message.
 void useImageCanvas(java.lang.String fileName)
          This loads the image from the specified @param fileName, which must be in the same directory as this class.
 void windowActivated(java.awt.event.WindowEvent evt)
           
 void windowClosed(java.awt.event.WindowEvent evt)
           
 void windowClosing(java.awt.event.WindowEvent evt)
           
 void windowDeactivated(java.awt.event.WindowEvent evt)
           
 void windowDeiconified(java.awt.event.WindowEvent evt)
           
 void windowIconified(java.awt.event.WindowEvent evt)
           
 void windowOpened(java.awt.event.WindowEvent evt)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageBox

public MessageBox(java.awt.event.ActionListener listener)
This convenience constructor is used to delare the listener that will be notified when a button is clicked. The listener must implement ActionListener.


MessageBox

public MessageBox()
This constructor is used for no listener, such as for a simple okay dialog.

Method Detail

main

public static void main(java.lang.String[] args)

run

public void run()
This prevents the caller from blocking on ask(), which if this class is used on an awt event thread would cause a deadlock.

Specified by:
run in interface java.lang.Runnable

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent evt)
Specified by:
actionPerformed in interface java.awt.event.ActionListener

windowClosing

public void windowClosing(java.awt.event.WindowEvent evt)
Specified by:
windowClosing in interface java.awt.event.WindowListener

windowClosed

public void windowClosed(java.awt.event.WindowEvent evt)
Specified by:
windowClosed in interface java.awt.event.WindowListener

windowDeiconified

public void windowDeiconified(java.awt.event.WindowEvent evt)
Specified by:
windowDeiconified in interface java.awt.event.WindowListener

windowIconified

public void windowIconified(java.awt.event.WindowEvent evt)
Specified by:
windowIconified in interface java.awt.event.WindowListener

windowOpened

public void windowOpened(java.awt.event.WindowEvent evt)
Specified by:
windowOpened in interface java.awt.event.WindowListener

windowActivated

public void windowActivated(java.awt.event.WindowEvent evt)
Specified by:
windowActivated in interface java.awt.event.WindowListener

windowDeactivated

public void windowDeactivated(java.awt.event.WindowEvent evt)
Specified by:
windowDeactivated in interface java.awt.event.WindowListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent evt)
Specified by:
keyTyped in interface java.awt.event.KeyListener

keyPressed

public void keyPressed(java.awt.event.KeyEvent evt)
Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent evt)
Specified by:
keyReleased in interface java.awt.event.KeyListener

setActionListener

public void setActionListener(java.awt.event.ActionListener listener)
This set the listener to be notified of button clicks and WindowClosing events.


setTitle

public void setTitle(java.lang.String title)

setFrame

public void setFrame(java.awt.Frame frame)
If a Frame is provided then it is used to instantiate the modal Dialog. Otherwise a temporary Frame is used. Providing a Frame will have the effect of putting the focus back on that Frame when the MessageBox is closed or a button is clicked.


setCloseWindowCommand

public void setCloseWindowCommand(java.lang.String command)
Sets the ActionCommand used in the ActionEvent when the user attempts to close the window. The window may be closed by clicking on "X", choosing Close from the window menu, or pressing the Escape key. The default command is "CloseRequested", which is just what a Close choice button would probably have as a command.


useImageCanvas

public void useImageCanvas(java.awt.Canvas imageCanvas)
This is handy for providing a small image that will be displayed to the left of the message.


useImageCanvas

public void useImageCanvas(java.lang.String fileName)
This loads the image from the specified @param fileName, which must be in the same directory as this class. For example @param fileName might be "LightBulb.gif".


addChoice

public void addChoice(java.lang.String label,
                      java.lang.String command)
The @param label will be used for the button and the

Parameters:
command - will be returned to the listener.

addChoice

public void addChoice(java.lang.String label)
A convenience method that assumes the command is the same as the label.


ask

public void ask(java.lang.String message)
One of the "ask" methods must be the last call when using a MessageBox. This is the simplest "ask" method. It presents the provided @param message.


askOkay

public void askOkay(java.lang.String message)
Same as ask(String message) except adds an "Okay" button.


askYesNo

public void askYesNo(java.lang.String message)
Same as ask(String message) except adds "Yes" and "No" buttons.



Copyright ? 2006 Brigham Young University, Configurable Computing Laboratory. All Rights Reserved.