CSCI A202 - Introduction to Programming (II)

Lecture 14: Recursion. Frames

We'll start with recursion.

When we are done we will move to understanding how paint works.

We'll discuss an example similar to this:

class Frame {
  protected String  myGC 
                 = "The Graphics Context from class Frame"; 
  protected int     width, height;
  protected boolean visible; 
  protected void    resize(int w, int h)   { 
    setSize(w, h); 
  protected void    refresh()              { 
  protected void    setVisible(boolean tF) { 
    visible = tF; 
  protected void    setSize(int w, int h)  { 
    width = w; 
    height = h; 
  public    void    paint(String gc) {
    System.out.println("Frame: I use\n  " 
                       + gc 
                       + " \nto draw my images."); 
public class Window extends Frame {

  public void paint(String graphicsContext) {
    System.out.println("Window: I use\n  " 
                       + graphicsContext 
                       + " \nto draw my images.");

  public static void main(String[] args) {

    Frame f = new Window();  // you have 
    f.setSize(100, 200);     // seen this
    f.setVisible(true);      // many times... 

    user(f);                 // you never ever see this
                             // but you know it happens
  private static void user(Frame f) {
    f.resize(200, 400); 
    // minimal interaction by the user simulated here

Notice: If you understand how the code above works then Also note: protected is like private, but allowing inheritance of the variable or method.