import javax.swing.JFrame;

/**
 * OurJFrame is a customized JFrame.
 * - OurJFrame is a subclass of JFrame.
 * - JFrame is a superclass of OurJFrame.
 * 
 * - public is an access modifier.  When a class
 *   is public, then it can be used by other classes.
 * - The class name is OurJFrame. Class names should
 *   start with uppercase letters.
 * - { indicates the start of the class definition
 * - } indicates the end of the class definition
 */
public class OurJFrame extends JFrame {
  
  /** Instance variable that stores the title of OurJFrame, as a String. */
  private String ourTitle = "Default title!";
      
  /**
   * The following is a constructor.  
   * It is invoked whenever you write "new OurJFrame(String)".
   * 
   * Creates a window with the given title,
   * with a default size 200x100,
   * and make the window visible.
   * 
   * Note: here "title" is called a parameter, not an argument.
   */
  public OurJFrame(String title) {
    this(title, 200, 100);
  }
  
  /**
   * The following is another constructor.  
   * It is invoked whenever you write "new OurJFrame(String, int, int)".
   * 
   * Creates a window with the given title, width, and height,
   * and make the window visible.
   */
  public OurJFrame(String title, int w, int h) {
    this.setTitle(title);
    this.setSize(w, h);
    this.setVisible(true);
  }
  
  /**
   * The following is a third constructor.  
   * It is invoked whenever you write "new OurJFrame()".
   * 
   * Creates a window with the DEFAULT title,
   * with a default size 200x100,
   * and make the window visible.
   */
  public OurJFrame() {
    this.setTitle(this.ourTitle);
    this.setSize(200, 100);
    this.setVisible(true);
    
  }
  
  /**
   * Returns the title of this OurJFrame, as a String.
   * 
   * Note: "String" indicates the return type of this function.
   */
  public String getOurTitle() {
    return this.ourTitle;
  }
  
  /**
   * This method will double the width of
   * the window.
   * - void indicates that this method is a procedure
   * Note that we can implement this without using w and h.
   */
  public void doubleWidth() {    
    // get the current width of the window
    int w = this.getWidth();

    // get the current height of the window
    int h = this.getHeight();
    
    // set the width to twice the current width, no change to height
    this.setSize(w * 2, h);
  }   
  
  /**
   * This method will switch the width and the height of the window.
   * 
   * - void indicates that it is a procedure.
   */
  public void flip() {
    int w = this.getWidth();
    int h = this.getHeight();
    
    this.setSize(h, w);
  }
  
  /**
   * This method will increase the window size to make it a square.
   * 
   * - void indicates that it is a procedure.
   */
  public void makeSquare() {
    int maxDim = Math.max(this.getWidth(), this.getHeight());
    
    this.setSize(maxDim, maxDim);
  }
    
}