import java.awt.*;

// A variation of a class that appears in Core Web
// Programming from Prentice Hall. May be freely used
// or adapted.
// 1998 Marty Hall, http://www.apl.jhu.edu/~hall/java/

public class SimpleRowLayout implements LayoutManager {
 
  public void addLayoutComponent(String s, Component c) {
  }
  
  public void removeLayoutComponent(Component c) {
  }

  public Dimension preferredLayoutSize(Container cont) {
    int count=0, maxWidth=0, maxHeight=0;
    Dimension componentSize;
    Component[] components = cont.getComponents();
    Component c;
    for(int i=0; i<components.length; i++) {
      c = components[i];
      componentSize = c.getPreferredSize();
      maxWidth = Math.max(componentSize.width, maxWidth);
      maxHeight = Math.max(componentSize.height,
                           maxHeight);
      count++;
    }
    return(new Dimension(count*maxWidth, maxHeight));
  }
  
  public Dimension minimumLayoutSize(Container cont) {
    return(preferredLayoutSize(cont));
  }
  
  public void layoutContainer(Container cont) {
    Component[] components = cont.getComponents();
    int width = cont.getSize().width/components.length,
      height= cont.getSize().height, left=0, top=0;
    Component c;
    for(int i=0; i<components.length; i++) {
      c = components[i];
      c.setBounds(left, top, width, height);
      left = left + width;
    }
  }
}

