home *** CD-ROM | disk | FTP | other *** search
/ Java 1996 August / Java - Summer 1996.iso / rockridge / ui / layout / example / GridBagEx1.java < prev    next >
Encoding:
Java Source  |  1995-11-13  |  1.8 KB  |  66 lines

  1. import java.awt.*;
  2. import java.util.*;
  3. import java.applet.Applet;
  4.  
  5. public class GridBagEx1 extends Applet {
  6.  
  7.     protected void makebutton(String name,
  8.                               GridBagLayout gridbag,
  9.                               GridBagConstraints c) {
  10.         Button button = new Button(name);
  11.         gridbag.setConstraints(button, c);
  12.         add(button);
  13.     }
  14.  
  15.     public void init() {
  16.         GridBagLayout gridbag = new GridBagLayout();
  17.         GridBagConstraints c = new GridBagConstraints();
  18.  
  19.         setFont(new Font("Helvetica", Font.PLAIN, 14));
  20.         setLayout(gridbag);
  21.    
  22.         c.fill = GridBagConstraints.BOTH;
  23.         c.weightx = 1.0;
  24.         makebutton("Button1", gridbag, c);
  25.         makebutton("Button2", gridbag, c);
  26.         makebutton("Button3", gridbag, c);
  27.  
  28.     c.gridwidth = GridBagConstraints.REMAINDER; //end row
  29.         makebutton("Button4", gridbag, c);
  30.  
  31.         c.weightx = 0.0;           //reset to the default
  32.         makebutton("Button5", gridbag, c); //another row
  33.  
  34.     c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last in row
  35.         makebutton("Button6", gridbag, c);
  36.  
  37.     c.gridwidth = GridBagConstraints.REMAINDER; //end row
  38.         makebutton("Button7", gridbag, c);
  39.  
  40.     c.gridwidth = 1;              //reset to the default
  41.     c.gridheight = 2;
  42.         c.weighty = 1.0;
  43.         makebutton("Button8", gridbag, c);
  44.  
  45.         c.weighty = 0.0;           //reset to the default
  46.     c.gridwidth = GridBagConstraints.REMAINDER; //end row
  47.     c.gridheight = 1;           //reset to the default
  48.         makebutton("Button9", gridbag, c);
  49.         makebutton("Button10", gridbag, c);
  50.  
  51.         resize(300, 100);
  52.     }
  53.  
  54.     public static void main(String args[]) {
  55.     Frame f = new Frame("GridBag Layout Example");
  56.     GridBagEx1 ex1 = new GridBagEx1();
  57.  
  58.     ex1.init();
  59.  
  60.     f.add("Center", ex1);
  61.     f.pack();
  62.     f.resize(f.preferredSize());
  63.     f.show();
  64.     }
  65. }
  66.