• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do i add Graphic Objects to JPanel while the programm is running  RSS feed

 
frank van schie
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dear Moose Saloon members,

I'm trying to create a paint like program in Java.
but i cant seem to figure out how to add objects to a JPanel/JFrame on user commands (like mouseclick).
any advice?

do i need to make a container?

oh and here is my object.

 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The usual approach is to create a member variable of type List<Shape> and in the paintComponent override, iterate over the list painting each shape.

If you need additional information not mandated by the Shape interface (such as Color), you could create a class that holds a Shape and the other information and use a List of instances of that class.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!