Any help would be appreciated. For some reason it isn't working please help A.S.A.P.
Code:
Code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.applet.*;
public class FinalProject extends JApplet implements MouseListener
{
private boolean mouseClick;
private Image[][] board;
Point empty;
public void init()
{
setBackground(Color.red);
board = new Image[4][4];
board[0][0] = getImage(getCodeBase(), "One.png");
board[0][1] = getImage(getCodeBase(), "Two.png");
board[0][2] = getImage(getCodeBase(), "Three.png");
board[0][3] = getImage(getCodeBase(), "Four.png");
board[1][0] = getImage(getCodeBase(), "Five.png");
board[1][1] = getImage(getCodeBase(), "Six.png");
board[1][2] = getImage(getCodeBase(), "Seven.png");
board[1][3] = getImage(getCodeBase(), "Eight.png");
board[2][0] = getImage(getCodeBase(), "Nine.png");
board[2][1] = getImage(getCodeBase(), "Ten.png");
board[2][2] = getImage(getCodeBase(), "Eleven.png");
board[2][3] = getImage(getCodeBase(), "Tweleve.png");
board[3][0] = getImage(getCodeBase(), "Thirteen.png");
board[3][1] = getImage(getCodeBase(), "Fourteen.png");
board[3][2] = getImage(getCodeBase(), "Fifteen.png");
board[3][3] = null;
Point empty = new Point(3,3);
mouseClick = false;
addMouseListener(this);
}
public void mouseClicked(MouseEvent e)
{
showStatus(""+e.getX()+ ", " + e.getY());
mouseClick = true;
Point toEmpty = new Point(e.getX()/100-1,e.getY()/100-1);
if ((toEmpty.getX() == (empty.getX())) || (toEmpty.getY() == (empty.getY())) && ((toEmpty.getX() == (empty.getX() + 1)) || (toEmpty.getY() == (empty.getY() + 1)) || (toEmpty.getX() == (empty.getX() - 1)) || (toEmpty.getY() == (empty.getY() - 1))))
{
board[(int)empty.getY()][(int)empty.getX()] = board[(int)toEmpty.getY()][(int)toEmpty.getX()];
board[(int)toEmpty.getY()][(int)toEmpty.getX()] = null;
empty = toEmpty;
}
repaint();
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void mousePressed(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
}
public void paint(Graphics g)
{
g.setColor(Color.lightGray);
g.fillRect(100,100, 400,400);
pieces(g);
Board(g);
}
public void Board(Graphics g)
{
g.setColor(Color.darkGray);
g.drawLine(100,100, 100,500);
g.drawLine(200,100, 200,500);
g.drawLine(300,100, 300,500);
g.drawLine(400,100, 400,500);
g.drawLine(500,100, 500,500);
g.drawLine(100,100, 500,100);
g.drawLine(100,200, 500,200);
g.drawLine(100,300, 500,300);
g.drawLine(100,400, 500,400);
g.drawLine(100,500, 500,500);
}
public void pieces(Graphics g)
{
g.drawImage(board[0][0],100,100,this);
g.drawImage(board[0][1],200,100,this);
g.drawImage(board[0][2],300,100,this);
g.drawImage(board[0][3],400,100,this);
g.drawImage(board[1][0],100,200,this);
g.drawImage(board[1][1],200,200,this);
g.drawImage(board[1][2],300,200,this);
g.drawImage(board[1][3],400,200,this);
g.drawImage(board[2][0],100,300,this);
g.drawImage(board[2][1],200,300,this);
g.drawImage(board[2][2],300,300,this);
g.drawImage(board[2][3],400,300,this);
g.drawImage(board[3][0],100,400,this);
g.drawImage(board[3][1],200,400,this);
g.drawImage(board[3][2],300,400,this);
g.drawImage(board[3][3],400,400,this);
}
}