views:

39

answers:

1

Hi Guys,

I have a 3 X 3 grid of JLabels of images. I constructed the grid using the grid layout.

I would like to move a round object which represents a car and place that object in a particular cell. So the grid will be like a background.

My questions are these:

1) How can i position this object on a specific cell based on the rows and column values? for instance if i want to put an object in [1][0].

2) How do i move this object to a different cell using the rows and column values. for instance if i want to move the object in [1][0] to [2][1]

Thank you all for your help.

+1  A: 

Instead of moving the labels, move the properties (the text or the image of them). That way, you can create a 2D array of labels. To move the text:

labels[2][1].setText (labels[1][0].getText ());
labels[1][0].setText ("");

[EDIT]

I would like to move a round object which represents a car and place that object in a particular cell. Am doing a sort of animation.

In that case, use a canvas. See this answer.

Aaron Digulla
Thanks for your reply. I would like to move a round object which represents a car and place that object in a particular cell. Am doing a sort of animation. So the grid will be like a background.
Edy Moore
Use a canvas. See my edits.
Aaron Digulla