import java.applet.*;
import java.awt.*;
public class TestApplet extends Applet {
 // The main method is included for testing only:
 public static void main (String args []) {             
  AppletTestorFrame f = new AppletTestorFrame("GridBagLayout Test"); 
  TestApplet p = new TestApplet(); p.init();            
  f.add("Center", p); f.resize(300, 200);  f.show();    
 }                                                      
 public void init () {
  GridBagLayout gbl = new GridBagLayout();
  setLayout(gbl);
  GridBagConstraints gbc = new GridBagConstraints();
  // Fill both ways:
  gbc.fill = GridBagConstraints.BOTH;
  // Allow expansion of all panels:
  gbc.weightx = 1.0;    
  gbc.weighty = 1.0;
  // Place panels:
  placePanel (0, 0, 1, 2, "A", gbl, gbc);
  placePanel (1, 0, 1, 1, "B", gbl, gbc);
  placePanel (0, 2, 1, 3, "C", gbl, gbc);
  placePanel (1, 1, 1, 4, "D", gbl, gbc);
  placePanel (2, 0, 1, 1, "E", gbl, gbc);
  placePanel (2, 1, 1, 1, "F", gbl, gbc);
  placePanel (2, 2, 1, 1, "G", gbl, gbc);
  placePanel (2, 3, 1, 1, "H", gbl, gbc);
  placePanel (2, 4, 1, 1, "I", gbl, gbc);
 }
 // Handle placement details:
 public void placePanel 
  (int x, int y, int w, int h, 
   String s, GridBagLayout l, GridBagConstraints c) {
  c.gridx = x;          c.gridwidth = w;
  c.gridy = y;          c.gridheight = h;
  SquarePanel p = new SquarePanel(s);
  l.setConstraints(p, c);   add(p);
 }
}
