import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;  // Need this library for images
import java.applet.*;

// This is a simple example of loading and displaying images in
// Java. The user is presented with a small section of an image,
// and may move around the image by clicking in the right or
// left half of the image.

public class VRpic extends Applet implements MouseListener {

  private Image skylineImage; // State variable to store image.
  private int x = 300; // Current portion of image to display.
  private int MAX = 600;
  private int INCREMENT = 10;

  public void init() {
    addMouseListener(this);

    // Download the image using getImage. The getDocumentBase method
    // returns the URL of the original web page (getCodeBase is often
    // used as well, if the image is in the same directory as the applet).
    // It is appended woth the second parameter to get the URL of
    // the image.

    skylineImage = getImage(getDocumentBase(), "skyline.jpg");
    }

  // When the mouse is clicked, either decrement x (if the mouse is
  // in the left half) or increment x (if the mouse is in the right
  // half), but only if we have not reached the edge of the image.
  // The repaint the image.

  public void mouseClicked (MouseEvent e) {
    if (e.getX() > (int)(getWidth()/2) && x + INCREMENT <= MAX) {
      x = x + INCREMENT;
      repaint();
      }
    if (e.getX() < (int)(getWidth()/2) && x - INCREMENT >= 0) {
      x = x - INCREMENT;
      repaint();
      }
    }
  public void mousePressed (MouseEvent e) {}
  public void mouseReleased (MouseEvent e) {}
  public void mouseEntered (MouseEvent e) {}
  public void mouseExited (MouseEvent e) {}
 
  // The drawImage draws the image. We use a complex form to be able
  // select a section of the image. The fist parameter is the Image
  // object, the next 4 are the coordinates of the top left corner and
  // the bottom right corner of the area where the image is to be
  // drawn on the applet, and the next 4 are the coordinates of the
  // top left and bottom right coordinates of the subsection of the
  // image to be drawn. The last parameter ("this") indicates that
  // the applet itself is to be notified when the image is drawn.

  public void paint(Graphics g) {
    g.drawImage(skylineImage, 0, 0, 100, 100, x, 0, 100+x, 100, this);
    }

  }

