home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / WDETOUR.BIN / QuitDialog.java < prev    next >
Text File  |  1997-08-27  |  4KB  |  137 lines

  1. /*
  2.     A basic extension of the java.awt.Dialog class
  3.  */
  4.  
  5. import java.awt.*;
  6. import java.awt.event.*;
  7.  
  8. public class QuitDialog extends Dialog
  9. {
  10.  
  11.     void QuitDialog_WindowClosing(java.awt.event.WindowEvent event)
  12.     {
  13.        hide();
  14.     }
  15.  
  16.     void yesButton_Clicked(java.awt.event.ActionEvent event)
  17.     {
  18.         Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new WindowEvent((java.awt.Window)getParent(), WindowEvent.WINDOW_CLOSING));
  19.     }
  20.  
  21.     void noButton_Clicked(java.awt.event.ActionEvent event)
  22.     {
  23.         //{{CONNECTION
  24.         // Clicked from noButton Hide the Dialog
  25.         hide();
  26.         //}}
  27.     }
  28.  
  29.     public QuitDialog(Frame parent, boolean modal)
  30.     {
  31.         super(parent, modal);
  32.  
  33.         // This code is automatically generated by Visual Cafe when you add
  34.         // components to the visual environment. It instantiates and initializes
  35.         // the components. To modify the code, only use code syntax that matches
  36.         // what Visual Cafe can generate, or Visual Cafe may be unable to back
  37.         // parse your Java file into its visual environment.
  38.         //{{INIT_CONTROLS
  39.         setLayout(null);
  40.         setVisible(false);
  41.         setSize(insets().left + insets().right + 337,insets().top + insets().bottom + 135);
  42.         setFont(new Font("Dialog", Font.PLAIN, 12));
  43.         setForeground(new Color(0));
  44.         setBackground(new Color(16777215));
  45.         yesButton = new java.awt.Button();
  46.         yesButton.setLabel(" Yes ");
  47.         yesButton.setBounds(insets().left + 72,insets().top + 80,79,22);
  48.         yesButton.setFont(new Font("Dialog", Font.BOLD, 12));
  49.         add(yesButton);
  50.         noButton = new java.awt.Button();
  51.         noButton.setLabel("  No  ");
  52.         noButton.setBounds(insets().left + 185,insets().top + 80,79,22);
  53.         noButton.setFont(new Font("Dialog", Font.BOLD, 12));
  54.         add(noButton);
  55.         label1 = new java.awt.Label("Do you really want to quit?",Label.CENTER);
  56.         label1.setBounds(insets().left + 78,insets().top + 33,180,23);
  57.         add(label1);
  58.         setTitle("A Basic Application - Quit");
  59.         //}}
  60.  
  61.         //{{REGISTER_LISTENERS
  62.         Window lWindow = new Window();
  63.         addWindowListener(lWindow);
  64.         Action lAction = new Action();
  65.         noButton.addActionListener(lAction);
  66.         yesButton.addActionListener(lAction);
  67.         //}}
  68.     }
  69.  
  70.     public void addNotify()
  71.     {
  72.         super.addNotify();
  73.  
  74.         if (fComponentsAdjusted)
  75.             return;
  76.  
  77.         // Adjust components according to the insets
  78.         setSize(insets().left + insets().right + getSize().width, insets().top + insets().bottom + getSize().height);
  79.         Component components[] = getComponents();
  80.         for (int i = 0; i < components.length; i++)
  81.         {
  82.             Point p = components[i].getLocation();
  83.             p.translate(insets().left, insets().top);
  84.             components[i].setLocation(p);
  85.         }
  86.         fComponentsAdjusted = true;
  87.     }
  88.  
  89.     boolean fComponentsAdjusted = false;
  90.  
  91.  
  92.     public QuitDialog(Frame parent, String title, boolean modal)
  93.     {
  94.         this(parent, modal);
  95.         setTitle(title);
  96.     }
  97.  
  98.     public synchronized void show()
  99.     {
  100.         Rectangle bounds = getParent().bounds();
  101.         Rectangle abounds = bounds();
  102.  
  103.         move(bounds.x + (bounds.width - abounds.width)/ 2,
  104.              bounds.y + (bounds.height - abounds.height)/2);
  105.  
  106.         super.show();
  107.     }
  108.  
  109.     //{{DECLARE_CONTROLS
  110.     java.awt.Button yesButton;
  111.     java.awt.Button noButton;
  112.     java.awt.Label label1;
  113.     //}}
  114.  
  115.     class Window extends java.awt.event.WindowAdapter
  116.     {
  117.         public void windowClosing(java.awt.event.WindowEvent event)
  118.         {
  119.             Object object = event.getSource();
  120.             if (object == QuitDialog.this)
  121.                 QuitDialog_WindowClosing(event);
  122.         }
  123.     }
  124.  
  125.     class Action implements java.awt.event.ActionListener
  126.     {
  127.         public void actionPerformed(java.awt.event.ActionEvent event)
  128.         {
  129.             Object object = event.getSource();
  130.             if (object == noButton)
  131.                 noButton_Clicked(event);
  132.             else if (object == yesButton)
  133.                 yesButton_Clicked(event);
  134.         }
  135.     }
  136. }
  137.