javabook
Class MessageBox

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Window
                    |
                    +--java.awt.Dialog
                          |
                          +--javabook.JavaBookDialog
                                |
                                +--javabook.MessageBox

public class MessageBox
extends JavaBookDialog
implements java.awt.event.ActionListener, java.awt.event.KeyListener

This dialog is for displaying a single line of text. This dialog is intended for displaying a short warning or error message. The width of this dialog is adjusted to fit the displayed message and the dialog is placed at the center of the screen.

This class is provided as freeware. You are free to use as provided or modify to your heart's content. But you use it at your own risk. No implied or explicit warranty is given.

See Also:
Serialized Form

Fields inherited from class javabook.JavaBookDialog
font, wasMoved
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
MessageBox()
          Default constructor.
MessageBox(java.awt.Frame owner)
          Creates a MessageBox with the designated owner.
MessageBox(java.awt.Frame owner, boolean modal)
          Creates a MessageBox box with the designated owner and modality.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Implements the required method of the ActionListener.
protected  void adjustSize()
          Place the label and button and adjust the dialog dimension
 void keyPressed(java.awt.event.KeyEvent e)
          Implements the required method of the KeyListener.
 void keyReleased(java.awt.event.KeyEvent e)
          Implements the required method of the KeyListener.
 void keyTyped(java.awt.event.KeyEvent e)
          Implements the required method of the KeyListener.
 void show(char character)
          Displays the char value after converting it to a string.
 void show(char character, int x, int y)
          Displays the char value after converting it to a string.
 void show(double number)
          Displays the real number after converting it to a string.
 void show(double number, int x, int y)
          Displays the real number after converting it to a string.
 void show(long number)
          Displays the integer value after converting it to a string.
 void show(long number, int x, int y)
          Displays the integer value after converting it to a string.
 void show(java.lang.String text)
          Displays the String value.
 void show(java.lang.StringBuffer text)
          Displays the StringBuffer value after conveting it to a string.
 void show(java.lang.StringBuffer text, int x, int y)
          Displays the StringBuffer value after conveting it to a string.
 void show(java.lang.String text, int x, int y)
          Displays the String value.
 
Methods inherited from class javabook.JavaBookDialog
moveToCenter, setVisible, windowActivated, windowClosed, windowClosing, windowDeactivated, windowDeiconified, windowIconified, windowOpened
 
Methods inherited from class java.awt.Dialog
addNotify, dispose, getTitle, hide, isModal, isResizable, paramString, setModal, setResizable, setTitle, show
 
Methods inherited from class java.awt.Window
addWindowListener, applyResourceBundle, applyResourceBundle, finalize, getFocusOwner, getInputContext, getLocale, getOwnedWindows, getOwner, getToolkit, getWarningString, isShowing, pack, postEvent, processEvent, processWindowEvent, removeWindowListener, setCursor, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFont, setLayout, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputMethodRequests, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MessageBox

public MessageBox()
Default constructor. The title is fixed to "Sample Java Application".

MessageBox

public MessageBox(java.awt.Frame owner)
Creates a MessageBox with the title "Sample Java Application".
Parameters:
owner - Frame object that owns this MessageBox

MessageBox

public MessageBox(java.awt.Frame owner,
                  boolean modal)
Creates a MessageBox box with the designated owner and modality.
Parameters:
owner - Frame object that owns this MessageBox
modal - true for modal and false for modeless MessageBox
Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Implements the required method of the ActionListener. Do not call this method. The Java virtual machine handles the action event processing. This method closes the dialog if the event is an OK button click event.
Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
e - the ActionEvent object.

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Implements the required method of the KeyListener. No response for the key typed event in this dialog.
Specified by:
keyTyped in interface java.awt.event.KeyListener
Parameters:
e - the KeyEvent object.

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Implements the required method of the KeyListener. No response for the key typed event in this dialog.
Specified by:
keyPressed in interface java.awt.event.KeyListener
Parameters:
e - the KeyEvent object.

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Implements the required method of the KeyListener. If the (pressed and) released key is ENTER key, then makes this dialog disappear.
Specified by:
keyReleased in interface java.awt.event.KeyListener
Parameters:
e - the KeyEvent object.

show

public void show(char character)
Displays the char value after converting it to a string.
Parameters:
character - the char value to display

show

public void show(long number)
Displays the integer value after converting it to a string.
Parameters:
number - the integer value to display

show

public void show(double number)
Displays the real number after converting it to a string.
Parameters:
number - the real value to display

show

public void show(java.lang.String text)
Displays the String value.
Parameters:
text - the String value to display

show

public void show(java.lang.StringBuffer text)
Displays the StringBuffer value after conveting it to a string.
Parameters:
text - the StringBuffer value to display

show

public void show(char character,
                 int x,
                 int y)
Displays the char value after converting it to a string. Position this dialog at (x, y).
Parameters:
character - the char value to display
x - the x-coordinate of the dialog position
y - the y-coordinate of the dialog position

show

public void show(long number,
                 int x,
                 int y)
Displays the integer value after converting it to a string. Position this dialog at (x, y).
Parameters:
number - the integer value to display
x - the x-coordinate of the dialog position
y - the y-coordinate of the dialog position

show

public void show(double number,
                 int x,
                 int y)
Displays the real number after converting it to a string. Position this dialog at (x, y).
Parameters:
number - the real value to display
x - the x-coordinate of the dialog position
y - the y-coordinate of the dialog position

show

public void show(java.lang.String text,
                 int x,
                 int y)
Displays the String value. Position this dialog at (x, y).
Parameters:
text - the String value to display
x - the x-coordinate of the dialog position
y - the y-coordinate of the dialog position

show

public void show(java.lang.StringBuffer text,
                 int x,
                 int y)
Displays the StringBuffer value after conveting it to a string. Position this dialog at (x, y).
Parameters:
text - the StringBuffer value to display
x - the x-coordinate of the dialog position
y - the y-coordinate of the dialog position

adjustSize

protected void adjustSize()
Place the label and button and adjust the dialog dimension
Overrides:
adjustSize in class JavaBookDialog