开发者

Positioning Objects Based On Row And Column Values

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].

开发者_JS百科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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜