Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Draw multiple circles on mouse click

 
George Holloway
Greenhorn
Posts: 3
Firefox Browser Netbeans IDE Postgres Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

So far i managed to get a circle to show itself on the JPanel when the mouse is clicked. The only problem i have is that it doesn't show multiple circles when clicked, instead it deletes the pervious one. I have a method called paint() where the graphics is drawn.


From what i read is that i need to make a array list of Shape at the beggining of my class and add a for loop in the paint() method.



For loop at the bottom of paint() method.


But this doesn't work as it displays text only since it is in front of the loop. Could you please show me some tutorial or another post here so i can solve this? Also some people override the paintGraphics() method, is this necessary? Or i can create my own method? Should i also store the cooridnates from mouseX and mouseY somewhere as well?
 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The correct method to override is paintComponent(....). I've never come across any paintGraphics method, where did you find tthat?

Did you add any Shapes to the ArrayList?

Learning resources:
http://docs.oracle.com/javase/tutorial/uiswing/painting/index.html
http://docs.oracle.com/javase/tutorial/2d/geometry/primitives.html
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic