import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;

public class grabber extends Applet {

   Image tiles[] = new Image[6];
   private int slotVar;
   private int tempVar;
   private int newVar;

  public void init() {

///////// From puzzle

    randNum testVar = new randNum();

    for (int i = 1; i < 6; i++) {
      slotVar = testVar.newNum();
      if (slotVar > 6 || myBoard.checkSlot(slotVar)) {
        while (slotVar > 6 || myBoard.checkSlot(slotVar)) {
          slotVar = testVar.newNum();
        }
      }
      myBoard.takeSlot(slotVar);
      System.out.println("You've got " + slotVar + ".");
    }
    System.out.println("The Empty: " + myBoard.whichEmpty());

    int theClicked = 4;
    int theOpen = myBoard.whichEmpty();
    if (myBoard.isAdjacent(theClicked,theOpen) == false) {
      System.out.println("Slot" + theClicked + " cannot move to " + theOpen);
    }
    else {
      System.out.println("Slot" + theClicked + " can move to " + theOpen);
    }

//////// End from puzzle

    setLayout(new BorderLayout());

    for (int i = 1; i < 6; i++) {
      tiles[i] = getImage(getDocumentBase(), "tile" + i + ".jpg");
    }

    Label l = new Label("This is where the project will be.");
    l.setBackground(Color.white);
    add(l, "South");

    Panel backGround = new Panel();
    backGround.setBackground(Color.white);
    add(backGround, "Center");

    backGround.setLayout(new GridLayout(1,2));

    myCanvas c = new myCanvas(tiles[1], tiles[2], tiles[3], tiles[4], tiles[5]);
    c.setBackground(Color.white);

    backGround.add(c);
    }// init
  } // class Grabber2

  //////////////////////////////////////

  class myCanvas extends Component implements MouseListener {

    Image s1,s2,s3,s4,s5;
    boolean isNew = true;
    board myBoard = new board();
    myCanvas(Image in1, Image in2, Image in3, Image in4, Image in5) {
      s1= in1;
      s2= in2;
      s3= in3;
      s4= in4;
      s5= in5;
      addMouseListener(this);
    }

   public void paint(Graphics g) {
     update(g);
   }

   public void update(Graphics g) {

     int h = s1.getHeight(this);
     int w = s1.getWidth(this);
     int xPos = 0;

     if (!isNew) { xPos = myBoard.getXCol2(); }
     else if (isNew) { xPos = myBoard.getXCol1(); }

      g.drawImage(s1, 0, 0, w, h, this);
      g.drawImage(s2, 101, 0, w, h, this);
      g.drawImage(s3, 0, 101, w, h, this);
      g.drawImage(s4, 101, 101, w, h, this);
      g.drawImage(s5, xPos, 202, w, h, this);

   } // update

   public void mouseClicked(MouseEvent evt) {
     int Xextent = evt.getX();
     int Yextent = evt.getY();
     if (isNew == false) { isNew = true; }
     else if (isNew == true) { isNew = false; }
     refresh();
   }
   public void mouseEntered(MouseEvent evt) {};
   public void mouseExited(MouseEvent evt) {};
   public void mousePressed(MouseEvent evt) {};
   public void mouseReleased(MouseEvent evt) {};

   public void refresh() {
	repaint();
	return;
  }

   }// class myCanvas


