File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Draw multiple circles on mouse click Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Draw multiple circles on mouse click" Watch "Draw multiple circles on mouse click" New topic
Author

Draw multiple circles on mouse click

George Holloway
Greenhorn

Joined: Jan 28, 2012
Posts: 3

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

Joined: May 03, 2008
Posts: 4523
    
    5

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


luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Draw multiple circles on mouse click
 
Similar Threads
Please Help?
random colour problems
Taking values from a text file inside paintcomponent
Having touble adding graphics to JPanel
Simple Gui Question (Head First Java)