Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Draw multiple circles on mouse click

Posts: 3
Netbeans IDE Firefox Browser Postgres Database
  • 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?
Posts: 5167
Netbeans IDE Opera Java
  • 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:
machines help you to do more, but experience less. Experience this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic