import javax.swing.*;
import java.awt.*;

/** A list of identical JFrames */
public class JFrameList {
  
  /** The width of a JFrame in the list */
  private final int WIDTH = 150;
  
  /** The height of a JFrame in the list */
  private final int HEIGHT = 150;
  
  /** The list of JFrames */
  private JFrame[] list;
  
  /** Construct a list of JFrames
   * @param size the number of JFrames in the list
   */
  public JFrameList(int size) {
    list = new JFrame[size];
    
    /* create each JFrame, and give it a size */
    for(int i = 0; i < size; i++) {
      list[i] = new JFrame();
      list[i].setSize(WIDTH, HEIGHT);
    }
  }
  
  
  /** Show the whole list of JFrames */
  public void display() {
    for(int i = 0; i < list.length; i++) {
      list[i].show();
    }
  }
  
  
  /** Set the location of each JFrames in the list so that they are spaced
   * evenly from top left to bottom right corners of the screen.
   */
  public void displayDownRight() {
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    int screenWidth = (int)d.getWidth();
    int screenHeight = (int)d.getHeight();
    
    int frameX = (screenWidth - WIDTH) / (list.length - 1);
    int frameY = (screenHeight - HEIGHT) / (list.length - 1);

    for(int i = 0; i < list.length; i++) {
      list[i].setLocation(i * frameX, i * frameY);
      list[i].show();
    }
  }

  
  /** Set the location of each JFrames in the list so that they are spaced
   * evenly from top right to bottom left corners of the screen.
   */
  public void displayDownLeft() {
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    int screenWidth = (int)d.getWidth();
    int screenHeight = (int)d.getHeight();
    
    int frameX = (screenWidth - WIDTH) / (list.length - 1);
    int frameY = (screenHeight - HEIGHT) / (list.length - 1);

    for(int i = 0; i < list.length; i++) {
      list[i].setLocation(screenWidth - WIDTH - (i * frameX), i * frameY);
      list[i].show();
    }
  }
}
