home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / vpojava.DLL / SOURCE / DIALOG < prev    next >
Text File  |  1998-03-18  |  2KB  |  98 lines

  1. /*
  2.     A basic extension of the java.awt.Dialog class
  3.  */
  4.  
  5. import java.awt.*;
  6.  
  7. public class Dialog1 extends Dialog
  8. {
  9.     public Dialog1(Frame parent, boolean modal)
  10.     {
  11.         super(parent, modal);
  12.  
  13.         // This code is automatically generated by Visual Cafe when you add
  14.         // components to the visual environment. It instantiates and initializes
  15.         // the components. To modify the code, only use code syntax that matches
  16.         // what Visual Cafe can generate, or Visual Cafe may be unable to back
  17.         // parse your Java file into its visual environment.
  18.         //{{INIT_CONTROLS
  19.         setLayout(null);
  20.         setSize(430,270);
  21.         setTitle("");
  22.         //}}
  23.  
  24.         //{{REGISTER_LISTENERS
  25.         SymWindow aSymWindow = new SymWindow();
  26.         this.addWindowListener(aSymWindow);
  27.         //}}
  28.     }
  29.     
  30.     public void addNotify()
  31.     {
  32.           // Record the size of the window prior to calling parents addNotify.
  33.         Dimension d = getSize();
  34.  
  35.         super.addNotify();
  36.  
  37.         if (fComponentsAdjusted)
  38.             return;
  39.  
  40.         // Adjust components according to the insets
  41.         setSize(insets().left + insets().right + d.width, insets().top + insets().bottom + d.height);
  42.         Component components[] = getComponents();
  43.         for (int i = 0; i < components.length; i++)
  44.         {
  45.             Point p = components[i].getLocation();
  46.             p.translate(insets().left, insets().top);
  47.             components[i].setLocation(p);
  48.         }
  49.         fComponentsAdjusted = true;
  50.     }
  51.  
  52.     // Used for addNotify check.
  53.     boolean fComponentsAdjusted = false;
  54.  
  55.  
  56.     public Dialog1(Frame parent, String title, boolean modal)
  57.     {
  58.         this(parent, modal);
  59.         setTitle(title);
  60.     }
  61.  
  62.     /**
  63.      * Shows or hides the component depending on the boolean flag b.
  64.      * @param b  if true, show the component; otherwise, hide the component.
  65.      * @see java.awt.Component#isVisible
  66.      */
  67.     public void setVisible(boolean b)
  68.     {
  69.         if(b)
  70.         {
  71.             Rectangle bounds = getParent().getBounds();
  72.             Rectangle abounds = getBounds();
  73.     
  74.             setLocation(bounds.x + (bounds.width - abounds.width)/ 2,
  75.                  bounds.y + (bounds.height - abounds.height)/2);
  76.         }
  77.         super.setVisible(b);
  78.     }
  79.  
  80.     //{{DECLARE_CONTROLS
  81.     //}}
  82.  
  83.     class SymWindow extends java.awt.event.WindowAdapter
  84.     {
  85.         public void windowClosing(java.awt.event.WindowEvent event)
  86.         {
  87.             Object object = event.getSource();
  88.             if (object == Dialog1.this)
  89.                 Dialog1_WindowClosing(event);
  90.         }
  91.     }
  92.     
  93.     void Dialog1_WindowClosing(java.awt.event.WindowEvent event)
  94.     {
  95.         setVisible(false);
  96.     }
  97. }
  98.