home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgLangD.iso
/
VCAFE.3.0A
/
Main.bin
/
DialogBox.java
< prev
next >
Wrap
Text File
|
1998-10-24
|
3KB
|
101 lines
package symantec.itools.awt.util.dialog;
import java.awt.Button;
import java.awt.Event;
import java.awt.Frame;
import java.awt.Dialog;
import java.awt.Rectangle;
/**
* This implements a non-resizable dialog box.
* It has an available button and closes itself as needed.
*/
public class DialogBox extends Dialog {
/**
* An available button.
*/
protected Button okButton;
/**
*
* Constructs a DialogBox with the given parent.
* @param f the frame of this dialogÆs parent
*/
public DialogBox(Frame f) {
this(f, false);
}
/**
* Constructs a DialogBox with the given parent and modality.
* @param f the frame of this dialogÆs parent
* @param modal true to construct a modal dialog, false to construct a
* non-modal dialog
*/
public DialogBox(Frame f, boolean modal) {
this(f, "", modal);
}
/**
* Constructs a DialogBox with the given parent, title, and modality.
* @param f the frame of this dialogÆs parent
* @param s the title for this dialog
* @param modal true to construct a modal dialog, false to construct a
* non-modal dialog
*/
public DialogBox(Frame f, String s, boolean modal) {
super(f, s, modal);
if ( modal )
setResizable(false);
else
setResizable(true);
}
/**
* Makes this component visible.
* <p>
* This is a standard Java AWT method which gets called to show this
* component. If this component was invisible due to a previous hide()
* call it makes this component visible again.
*/
public void show() {
Rectangle bounds = getParent().bounds();
Rectangle abounds = bounds();
move(bounds.x + (bounds.width - abounds.width) / 2,
bounds.y + (bounds.height - abounds.height) /2);
super.show();
}
/**
* Hides and disposes of the dialog.
*/
protected void closeDialog() {
hide();
dispose();
}
/**
* Processes events for this component.
* <p>
* This is a standard Java AWT method which gets called by the AWT to
* handle this component's events. The default handler for components
* dispatches to one of the following methods as needed: action(),
* gotFocus(), lostFocus(), keyDown(), keyUp(), mouseEnter(), mouseExit(),
* mouseMove(), mouseDrag(), mouseDown(), or mouseUp().
*
* @param event the event to handle
* @return true if the event was handled and no further action is needed,
* false to pass the event to this component's parent
*/
public boolean handleEvent(Event event) {
if ((event.target == okButton && event.id == Event.ACTION_EVENT) ||
(event.target == this && event.id == Event.WINDOW_DESTROY))
closeDialog();
return super.handleEvent(event);
}
}