home *** CD-ROM | disk | FTP | other *** search
/ Java 1996 August / Java - Summer 1996.iso / windows / doc / ui / layout / example / gridbagwindow.000 < prev    next >
Encoding:
Text File  |  1996-02-26  |  3.3 KB  |  116 lines

  1. <!--NewPage-->
  2. <html>
  3. <head>
  4. <title>GridBagWindow.java</title>
  5. </head>
  6. <body>
  7. <p>
  8. <hr size=4>
  9.  
  10. <h2>
  11.     GridBagWindow.java
  12. </h2>
  13. <p>
  14. <blockquote>
  15.  
  16. <pre>
  17.  
  18. /*
  19.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  20.  *
  21.  * Permission to use, copy, modify, and distribute this software
  22.  * and its documentation for NON-COMMERCIAL purposes and without
  23.  * fee is hereby granted provided that this copyright notice
  24.  * appears in all copies. Please refer to the file "copyright.html"
  25.  * for further important copyright and licensing information.
  26.  *
  27.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  28.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  29.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  30.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  31.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  32.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  33.  */
  34. import java.awt.*;
  35.  
  36. public class GridBagWindow extends Frame {
  37.     private boolean inAnApplet = true;
  38.  
  39.     protected void makebutton(String name,
  40.                               GridBagLayout gridbag,
  41.                               GridBagConstraints c) {
  42.         Button button = new Button(name);
  43.         gridbag.setConstraints(button, c);
  44.         add(button);
  45.     }
  46.  
  47.     public GridBagWindow() {
  48.         GridBagLayout gridbag = new GridBagLayout();
  49.         GridBagConstraints c = new GridBagConstraints();
  50.  
  51.         setFont(new Font("Helvetica", Font.PLAIN, 14));
  52.         setLayout(gridbag);
  53.    
  54.         c.fill = GridBagConstraints.BOTH;
  55.         c.weightx = 1.0;
  56.         makebutton("Button1", gridbag, c);
  57.         makebutton("Button2", gridbag, c);
  58.         makebutton("Button3", gridbag, c);
  59.  
  60.     c.gridwidth = GridBagConstraints.REMAINDER; //end row
  61.         makebutton("Button4", gridbag, c);
  62.  
  63.         c.weightx = 0.0;           //reset to the default
  64.         makebutton("Button5", gridbag, c); //another row
  65.  
  66.     c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last in row
  67.         makebutton("Button6", gridbag, c);
  68.  
  69.     c.gridwidth = GridBagConstraints.REMAINDER; //end row
  70.         makebutton("Button7", gridbag, c);
  71.  
  72.     c.gridwidth = 1;              //reset to the default
  73.     c.gridheight = 2;
  74.         c.weighty = 1.0;
  75.         makebutton("Button8", gridbag, c);
  76.  
  77.         c.weighty = 0.0;           //reset to the default
  78.     c.gridwidth = GridBagConstraints.REMAINDER; //end row
  79.     c.gridheight = 1;           //reset to the default
  80.         makebutton("Button9", gridbag, c);
  81.         makebutton("Button10", gridbag, c);
  82.     }
  83.  
  84.     public synchronized boolean handleEvent(Event e) {
  85.         if (e.id == Event.WINDOW_ICONIFY) {//DOESN'T seem to be necessary
  86.             hide(); 
  87.             return true;
  88.         }
  89.         if (e.id == Event.WINDOW_DESTROY) {
  90.             if (inAnApplet) {
  91.                 dispose();
  92.                 return true;
  93.             } else {
  94.                 System.exit(0);
  95.             }
  96.         }   
  97.         return super.handleEvent(e);
  98.     }
  99.  
  100.     public static void main(String args[]) {
  101.     GridBagWindow window = new GridBagWindow();
  102.         window.inAnApplet = false;
  103.  
  104.     window.setTitle("GridBagWindow Application");
  105.     window.pack();
  106.     window.show();
  107.     }
  108. }
  109. </pre>
  110. </blockquote>
  111. <p>
  112. <hr size=4>
  113. <p>
  114. </body>
  115. </html>
  116.