home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / QuitDialog.java < prev    next >
Encoding:
Java Source  |  1996-12-07  |  2.0 KB  |  77 lines

  1. /*
  2.     A basic extension of the java.awt.Dialog class
  3.  */
  4.  
  5. import java.awt.*;
  6.  
  7. public class QuitDialog extends Dialog {
  8.     void yesButton_Clicked(Event event) {
  9.         getParent().handleEvent(new Event(this, Event.WINDOW_DESTROY, null));
  10.     }
  11.  
  12.     void noButton_Clicked(Event event) {
  13.         //{{CONNECTION
  14.         // Clicked from noButton Hide the Dialog
  15.         hide();
  16.         //}}
  17.     }
  18.  
  19.     public QuitDialog(Frame parent, boolean modal) {
  20.  
  21.         super(parent, modal);
  22.  
  23.         //{{INIT_CONTROLS
  24.         setLayout(new FlowLayout(FlowLayout.CENTER,20,35));
  25.         addNotify();
  26.         resize(insets().left + insets().right + 317,insets().top + insets().bottom + 97);
  27.         setFont(new Font("Dialog", Font.BOLD, 12));
  28.         setForeground(new Color(0));
  29.         setBackground(new Color(16777215));
  30.         yesButton = new java.awt.Button(" Yes ");
  31.         yesButton.reshape(insets().left + 112,insets().top + 35,44,21);
  32.         yesButton.setFont(new Font("Dialog", Font.BOLD, 12));
  33.         add(yesButton);
  34.         noButton = new java.awt.Button(" No  ");
  35.         noButton.reshape(insets().left + 161,insets().top + 35,39,21);
  36.         noButton.setFont(new Font("Dialog", Font.BOLD, 12));
  37.         add(noButton);
  38.         setTitle("Really Quit?");
  39.         setResizable(false);
  40.         //}}
  41.     }
  42.  
  43.     public QuitDialog(Frame parent, String title, boolean modal) {
  44.         this(parent, modal);
  45.         setTitle(title);
  46.     }
  47.  
  48.     public synchronized void show() {
  49.         Rectangle bounds = getParent().bounds();
  50.         Rectangle abounds = bounds();
  51.  
  52.         move(bounds.x + (bounds.width - abounds.width)/ 2,
  53.              bounds.y + (bounds.height - abounds.height)/2);
  54.  
  55.         super.show();
  56.     }
  57.  
  58.     public boolean handleEvent(Event event) {
  59.         if(event.id == Event.WINDOW_DESTROY) {
  60.             hide();
  61.             return true;
  62.         }
  63.         if (event.target == noButton && event.id == Event.ACTION_EVENT) {
  64.             noButton_Clicked(event);
  65.         }
  66.         if (event.target == yesButton && event.id == Event.ACTION_EVENT) {
  67.             yesButton_Clicked(event);
  68.         }
  69.         return super.handleEvent(event);
  70.     }
  71.  
  72.     //{{DECLARE_CONTROLS
  73.     java.awt.Button yesButton;
  74.     java.awt.Button noButton;
  75.     //}}
  76. }
  77.