• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Movable Objects

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there

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 ]
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
reply
    Bookmark Topic Watch Topic
  • New Topic