home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / VCSAMPL.BIN / QuitDialog.java < prev    next >
Text File  |  1997-09-09  |  5KB  |  163 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.        dispose();
  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 dispose the Dialog
  25.         dispose();
  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.         GridBagLayout gridBagLayout;
  40.         gridBagLayout = new GridBagLayout();
  41.         setLayout(gridBagLayout);
  42.         setVisible(false);
  43.         setSize(insets().left + insets().right + 337,insets().top + insets().bottom + 135);
  44.         setBackground(new Color(12632256));
  45.         yesButton = new java.awt.Button();
  46.         yesButton.setLabel(" Yes ");
  47.         yesButton.setBounds(insets().left + 63,insets().top + 89,41,23);
  48.         yesButton.setFont(new Font("Dialog", Font.BOLD, 12));
  49.         GridBagConstraints gbc;
  50.         gbc = new GridBagConstraints();
  51.         gbc.gridx = 0;
  52.         gbc.gridy = 1;
  53.         gbc.weightx = 1.0;
  54.         gbc.weighty = 1.0;
  55.         gbc.fill = GridBagConstraints.NONE;
  56.         gbc.insets = new Insets(0,0,0,0);
  57.         ((GridBagLayout)getLayout()).setConstraints(yesButton, gbc);
  58.         add(yesButton);
  59.         noButton = new java.awt.Button();
  60.         noButton.setLabel("  No  ");
  61.         noButton.setBounds(insets().left + 230,insets().top + 89,42,23);
  62.         noButton.setFont(new Font("Dialog", Font.BOLD, 12));
  63.         gbc = new GridBagConstraints();
  64.         gbc.gridx = 1;
  65.         gbc.gridy = 1;
  66.         gbc.weightx = 1.0;
  67.         gbc.weighty = 1.0;
  68.         gbc.fill = GridBagConstraints.NONE;
  69.         gbc.insets = new Insets(0,0,0,0);
  70.         ((GridBagLayout)getLayout()).setConstraints(noButton, gbc);
  71.         add(noButton);
  72.         label1 = new java.awt.Label("Do you really want to quit?",Label.CENTER);
  73.         label1.setBounds(insets().left + 90,insets().top + 22,156,23);
  74.         gbc = new GridBagConstraints();
  75.         gbc.gridx = 0;
  76.         gbc.gridy = 0;
  77.         gbc.gridwidth = 2;
  78.         gbc.weightx = 1.0;
  79.         gbc.weighty = 1.0;
  80.         gbc.fill = GridBagConstraints.NONE;
  81.         gbc.insets = new Insets(0,0,0,0);
  82.         ((GridBagLayout)getLayout()).setConstraints(label1, gbc);
  83.         add(label1);
  84.         setTitle("A Basic Application - Quit");
  85.         //}}
  86.  
  87.         //{{REGISTER_LISTENERS
  88.         Window lWindow = new Window();
  89.         addWindowListener(lWindow);
  90.         Action lAction = new Action();
  91.         noButton.addActionListener(lAction);
  92.         yesButton.addActionListener(lAction);
  93.         //}}
  94.     }
  95.  
  96.     public void addNotify()
  97.     {
  98.         super.addNotify();
  99.  
  100.         if (fComponentsAdjusted)
  101.             return;
  102.  
  103.         // Adjust components according to the insets
  104.         setSize(insets().left + insets().right + getSize().width, insets().top + insets().bottom + getSize().height);
  105.         Component components[] = getComponents();
  106.         for (int i = 0; i < components.length; i++)
  107.         {
  108.             Point p = components[i].getLocation();
  109.             p.translate(insets().left, insets().top);
  110.             components[i].setLocation(p);
  111.         }
  112.         fComponentsAdjusted = true;
  113.     }
  114.  
  115.     boolean fComponentsAdjusted = false;
  116.  
  117.  
  118.     public QuitDialog(Frame parent, String title, boolean modal)
  119.     {
  120.         this(parent, modal);
  121.         setTitle(title);
  122.     }
  123.  
  124.     public synchronized void show()
  125.     {
  126.         Rectangle bounds = getParent().bounds();
  127.         Rectangle abounds = bounds();
  128.  
  129.         move(bounds.x + (bounds.width - abounds.width)/ 2,
  130.              bounds.y + (bounds.height - abounds.height)/2);
  131.  
  132.         super.show();
  133.     }
  134.  
  135.     //{{DECLARE_CONTROLS
  136.     java.awt.Button yesButton;
  137.     java.awt.Button noButton;
  138.     java.awt.Label label1;
  139.     //}}
  140.  
  141.     class Window extends java.awt.event.WindowAdapter
  142.     {
  143.         public void windowClosing(java.awt.event.WindowEvent event)
  144.         {
  145.             Object object = event.getSource();
  146.             if (object == QuitDialog.this)
  147.                 QuitDialog_WindowClosing(event);
  148.         }
  149.     }
  150.  
  151.     class Action implements java.awt.event.ActionListener
  152.     {
  153.         public void actionPerformed(java.awt.event.ActionEvent event)
  154.         {
  155.             Object object = event.getSource();
  156.             if (object == noButton)
  157.                 noButton_Clicked(event);
  158.             else if (object == yesButton)
  159.                 yesButton_Clicked(event);
  160.         }
  161.     }
  162. }
  163.