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() {

}

[3188 byte] By [Duckmana] at [2007-11-27 1:15:25]
# 1

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() {

}

Duckmana at 2007-7-11 23:50:46 > top of Java-index,Security,Cryptography...
# 2
Make DisplayPanel a separate class completely, not an inner class of PuyoPuyo. You should do all the image loading the DisplayPanel class, not PuyoPuyo.
CaptainMorgan08a at 2007-7-11 23:50:46 > top of Java-index,Security,Cryptography...
# 3
how would i exactly do that, do i have to make a separate .java file with to make DisplayPanel a separate class from PuyoPuyo? Remember im a noob at java
Duckmana at 2007-7-11 23:50:46 > top of Java-index,Security,Cryptography...
# 4
You could put it in its own .java file. Try looking for some tutorials.
CaptainMorgan08a at 2007-7-11 23:50:46 > top of Java-index,Security,Cryptography...
# 5
actually i ended up getting the images to load, i just put them on a website lol, now to actually make the game work lol
Duckmana at 2007-7-11 23:50:46 > top of Java-index,Security,Cryptography...