import java.awt.*;

// This appears in Core Web Programming from
// Prentice Hall Publishers, and may be freely used
// or adapted. 1997 Marty Hall, hall@apl.jhu.edu.

/** An application that tiles an image using either
 *  a default width/height or values supplied via
 *  command line arguments.
 */

public class JavaJump2 extends Frame {
  public static void main(String[] args) {
    // Parse input parameters
    int imageWidth = 100;
    if (args.length > 0)
      imageWidth = Integer.parseInt(args[0]);
    int imageHeight = 120;
    if (args.length > 1)
      imageHeight = Integer.parseInt(args[1]);
    // Build the class
    new JavaJump2(imageWidth, imageHeight);
  }
    
  private Image jumpingJava;
  private int imageWidth, imageHeight;
  private int top = 0;
  
  public JavaJump2(int imageWidth, int imageHeight) {
    super("Great Jumping Java!"); // Frame constructor
    String imageFile = System.getProperty("user.dir") +
                       "/images/Jumping-Java.gif";
    jumpingJava = getToolkit().getImage(imageFile);
    this.imageWidth = imageWidth;
    this.imageHeight = imageHeight;
    setBackground(Color.white);
    resize(700, 500);
    show();
  }

  public void paint(Graphics g) {
    int width = size().width;
    int height = size().height;
    for(int y=0; y<height; y=y+imageHeight) 
      for(int x=0; x<width; x=x+imageWidth)
        g.drawImage(jumpingJava,
                    x, y, imageWidth, imageHeight, this);
  }

  /** Honor requests to quit the window. */
  
  public boolean handleEvent(Event event) {
    if (event.id == Event.WINDOW_DESTROY)
      System.exit(0);
    return(super.handleEvent(event));
  }
}

