loading image from file not from URL
I am not sure what exactly im doing wrong but i cannot get images to load into my applet. I am trying to load these images from my computer and I am not exactly sure how to do it. Here is my code:
public class PuyoPuyo extends JApplet implements KeyListener, FocusListener, MouseListener{
static final int SQUARE_SIZE = 40;
static final short CLEAR = 0;
static final short BLUE = 1;
static final short GREEN = 2;
static final short RED = 3;
static final short YELLOW = 4;
Image[][] board;
Image blueImage;
Image redImage;
Image yellowImage;
Image greenImage;
Image whiteImage;
Color squareColor;
int imgX,imgY;
int squareTop, squareLeft;
boolean focussed = false;
DisplayPanel grid;
public void init() {
board = new Image[12][6];
setSize(100,150);
squareTop = getSize().height / 2 - SQUARE_SIZE / 2;
squareLeft = getSize().width / 2 - SQUARE_SIZE / 2;
squareColor = Color.red;
blueImage = this.getImage(getDocumentBase(), "puyo_blue.JPG");
greenImage = this.getImage(getDocumentBase(), "puyo_green.JPG");
redImage = this.getImage(getDocumentBase(), "puyo_red.JPG");
yellowImage = this.getImage(getDocumentBase(), "puyo_yellow.JPG");
whiteImage = this.getImage(getDocumentBase(), "puyo_white.JPG");
grid = new DisplayPanel();
setContentPane(grid);
grid.setBackground(Color.white);
grid.addFocusListener(this);
grid.addKeyListener(this);
grid.addMouseListener(this);
}
class DisplayPanel extends JPanel {
Image blueImage;
Image redImage;
Image yellowImage;
Image greenImage;
public void paint(Graphics g) {
super.paint(g);
if (focussed)
g.setColor(Color.cyan);
else
g.setColor(Color.lightGray);
int width = getSize().width;
int height = getSize().height;
//int imgX = getSize().width/2 - blueImage.getWidth(this);
//int imgY = getSize().height/2 - blueImage.getHeight(this);
g.drawImage(blueImage, squareLeft, squareTop, this);
g.drawImage(greenImage, squareLeft, squareTop, this);
g.drawImage(redImage, squareLeft, squareTop, this);
g.drawImage(yellowImage, squareLeft, squareTop, this);
printArray(board, g);
g.drawRect(0,0,width-1,height-1);
g.drawRect(1,1,width-3,height-3);
g.drawRect(2,2,width-5,height-5);
g.setColor(squareColor);
g.fillRect(squareLeft, squareTop, SQUARE_SIZE * 2, SQUARE_SIZE);
for (int row = 0; row < 12; row++) {
for (int col = 0; col < 6; col++) {
board[row][col] = redImage;
}
}
if (!focussed) {
g.setColor(Color.magenta);
g.drawString("Click to begin",7,20);
}
}
public void printArray(Image a[][], Graphics g) {
int x = 0;
int y = -15;
for (int row = 0; row < 12; row++) {
for (int col = 0; col < 6; col++) {
g.drawImage(a[row][col], x, y, this);
x +=15;
}
x = 25;
y += 15;
}
}
}
public void checkFourInARow() {
}

