I have a JFrame with a JPanel placed on it. The JFrame is 400x400 and the JPanel is 300x300.
I now want to put an object on the panel ie, a rectangle in horizontal position sized at a height of 50 and length of 100.
Basically the JPanel is to be imagined as a 6x6 grid. Its the beginning stages of the Rush Hour game - I want to first get one object moving and then once that is sorted i will then edit it and take it further by adding other cars (rectangles in this case)
I have no idea how to add a rectangle shape to the panel that is moveable by clicking on it and dragging. I know I need to use a MouseListener. I want the rectangle to be able to move in incriments of 50 as 300/6 is obviously 50.
I have made a drawing program before using dragging/rubber banding but this is obviously going to be a bit different.
Here is the code I have at the moment coded in Netbeans - Any help anyone could give me would be much appreciated as at the moment I am at a dead end.
[ November 08, 2007: Message edited by: Steven Gibbs ]
Well just quickly putting something together you could do something like this. This gives a simple example of moving objects around the screen in a grid like fashion. Just click and drag the squares around. Hope this helps.