import javax.swing.*;
/**
 * a subclass of JFrame that cover the original JFrame
 * that divides the original JFrame into quarters
 * in different ways.
 */
public class QuarteringWindow extends JFrame {
  
  /**
   * four small windows that can cover this JFrame
   */
  private JFrame w1= new JFrame(),
    w2= new JFrame(),
    w3= new JFrame(),
    w4= new JFrame();
  
  /**
   * create four new JFrames that cover the original
   * JFrame.  The new JFrames form a grid.  Each of
   * the new JFrames is one quarter the size of the
   * original.
   */
  public void quarter() {
    int width= getWidth() /2, height= getHeight()/2;
     // start at this window's top left corner
    w1.setLocation(getX(), getY());
    // width and height are halved.
    w1.setSize(width, height);
    // start at this window's top edge, half
    // way across
    w2.setLocation(getX() + width, getY());
    w2.setSize(width, height);
    w3.setLocation(getX(), getY() + height);
    w3.setSize(width, height);
    w4.setLocation(getX() + width,
                    getY() + height);
    w4.setSize(width, height);
    w1.show();
    w2.show();
    w3.show();
    w4.show();
  }
  
  /**
   * create four new JFrames that cover the original
   * JFrame.  The new JFrames are four vertical
   * stripes that cover the original JFrame.
   */
  public void quarterVertical() {
    int width= getWidth()/4;
    w1.setLocation(getX(), getY());
    w1.setSize(width, getHeight());
    w2.setLocation(getX() + width, getY());
    w2.setSize(width, getHeight());
    w3.setLocation(getX() + width * 2,
                   getY());
    w3.setSize(width, getHeight());
    w4.setLocation(getX() + width * 3,
                   getY());
    w4.setSize(width, getHeight());
    w1.show();
    w2.show();
    w3.show();
    w4.show();
  }
  
  /**
   * create four new JFrames that cover the original
   * JFrame.  The new JFrames are like four
   * horizontal stripes of equal width
   */
  public void quarterHorizontal() {
    int height= getHeight()/4;
    w1.setLocation(getX(), getY());
    w1.setSize(getWidth(), height);
    w2.setLocation(getX(), getY() + height);
    w2.setSize(getWidth(), height);
    w3.setLocation(getX(), getY() + 2 * height);
    w3.setSize(getWidth(), height);
    w4.setLocation(getX(), getY() + 3 * height);
    w4.setSize(getWidth(), height);
    w1.show();
    w2.show();
    w3.show();
    w4.show();
  }
}