home *** CD-ROM | disk | FTP | other *** search
/ Java by Example / jbecd.bin / JBE-CD / Mje / HVPanel.java < prev    next >
Encoding:
Java Source  |  1996-04-08  |  784 b   |  39 lines

  1. //
  2. // Horizontal and Vertical Panel
  3. //
  4.  
  5. import java.awt.*;
  6.  
  7. class HVPanel extends Panel {
  8.   static final int HORIZONTAL = 0;
  9.   static final int VERTICAL = 1;
  10.  
  11.   HGridLayout hgrid;
  12.   VGridLayout vgrid;
  13.   int orientation;
  14.  
  15.   public HVPanel(int orient, int border, int gap, int left) {
  16.     orientation = orient;
  17.     Insets is = new Insets(border, border, border, border);
  18.  
  19.     if (orient == HORIZONTAL) {
  20.       hgrid = new HGridLayout(is, gap, left);
  21.       setLayout(hgrid);
  22.     }
  23.     else {
  24.       vgrid = new VGridLayout(is, gap, left);
  25.       setLayout(vgrid);
  26.     }
  27.   }
  28.  
  29.   public Component add(int size, Component comp) {
  30.     if (orientation == HORIZONTAL)
  31.       hgrid.setConstraints(comp, size);
  32.     else
  33.       vgrid.setConstraints(comp, size);
  34.  
  35.     add(comp);
  36.     return comp;
  37.   }
  38. }
  39.