It's not a secret anymore!
The moose likes Swing / AWT / SWT and the fly likes Paint program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Paint program" Watch "Paint program" New topic

Paint program

aarti bashyam

Joined: Aug 21, 2008
Posts: 1
I am writing a program where if the user clicks, it should draw a point. The following code does not seem to work properly. If I click, it draws a point but vanishes later on. I tried using paint and paint component but I am not able to use them. Please help!!

Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2447
Please use the "Code" tags when posting code.

You can start with the Swing tutorial on Custom Painting for a working example that you can modify.
Yunnan Zhou
Ranch Hand

Joined: May 04, 2011
Posts: 31

just remove repaint() in you method mousePressed() and try again.but it's not a good way.
if you want your points stay and not must save them in a collection .everytimes you press ,repaint all point which in you collection.

I'am a Chinese.I like Java.Hello.
Darryl Burke

Joined: May 03, 2008
Posts: 5115

aarti, welcome to the Ranch! We don't have too many rules around here, but we do ask that you BeForthrightWhenCrossPostingToOtherSites <-- link

luck, db
There are no new questions, but there may be new answers.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46344
I think this discussion ought to be moved to our GUIs forum
I agree. Here's the link:
subject: Paint program
It's not a secret anymore!