• Post Reply Bookmark Topic Watch Topic
  • New Topic

Movable paint objects within JPanel

 
Bob Mazz
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm writing a program where I need to (with every JMenu item click) create a new rectangle object. Im just unsure about how to create a new mouse-movable object so it is displayed within the JPanel. Any related help would be great. Cheers to Nate btw who gave me a nudge in the right direction!
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're going to need to use one of the Collections classes like ArrayList, LinkedList or Vector for this... if you're using a separate panel for each then this can hold references to the JPanel objects. If you're drawing each object as a rectangle inside a component's paintComponent() method you can store them as Rectangles. In either case, you're just going to construct a new JPanel or Rectangle, add it to the list, and repaint.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!