moving a shape

Hi,

I have a maze and I want to make it possible for a charachter (an image) to run through the maze. Not taking the walls in acount, he may run through walls, i don't mind i'll program that later.

The maze itself is actually a 2D array filled with 1, 0 values. 1 represents a wall, 0 floor. I have the array run through by two for loops to change the 1 values to wallimages and the 0 values to floorimages. Everything from the maze is drawn in my paintComponent(Graphics g) method.

But I think that's not the main point; my main question is how can I make an image and when I press a button or something, the location of the image is changed. I always have to be able to know the current position of the image though.

Greetz Daan

[766 byte] By [D-a-a-na] at [2007-11-27 4:01:36]
# 1
> how can I make an image and when I press a button or something, the location of the image is changedimage.setLocation(....);
camickra at 2007-7-12 9:06:20 > top of Java-index,Desktop,Core GUI APIs...
# 2

There doesn't exist such a method for an image. The only graphics where such methods exist are shapes like a rectangle or an oval i quess.

EDIT: I could make a method draw and call it every time the image has to be moved. Something like this:

private void draw(int x, int y, Graphics g)

{

g.drawImage(heroimg, x*CELLSIZE, y*CELLSIZE,CELLSIZE,CELLSIZE, this);

}

But offcorse this will always let a copy at the orignal place behind so I get a trail. How do i solve this?

Greetz Daan

Message was edited by:

D-a-a-n

D-a-a-na at 2007-7-12 9:06:20 > top of Java-index,Desktop,Core GUI APIs...
# 3
> There doesn't exist such a method for an imageAdd your image to a JLabel and move the JLabel around the screen.
camickra at 2007-7-12 9:06:20 > top of Java-index,Desktop,Core GUI APIs...