aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes cannot draw graphics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "cannot draw graphics" Watch "cannot draw graphics" New topic

cannot draw graphics

Jonathan Keller

Joined: Dec 01, 2011
Posts: 2
The goal of this program is to change the background to yellow when the mouse enters, change the background to black when the mouse exits, create a small circle on left click, and create a large circle on right click. The mouse enter and exit methods work just fine, but i cannot get it to draw the circles. Any help would be appreciated.

Tim Moores

Joined: Sep 21, 2011
Posts: 2408
If you use Swing components (the ones named J...) you need to override paintComponent, not paint. See for details.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4339

tim is correct.
thanks jonathan for showing me how to tell which button was clicked.

Visit my download page
Jonathan Keller

Joined: Dec 01, 2011
Posts: 2
Maybe I am not understanding correctly, but isn't that why the first line of the paint method is super.paint(g)?
Tim Moores

Joined: Sep 21, 2011
Posts: 2408
No, paint should not be calling super.paint. And as I said, it's the wrong method for Swing components to override anyway.
Rob Spoor

Joined: Oct 27, 2005
Posts: 19557

Since this is a JFrame you can't override paintComponent because JFrame doesn't have a paintComponent method. Try creating a JPanel subclass instead:

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: cannot draw graphics
Similar Threads
Mousedragging not working after updating the array.
Applet help
Messagebox with Mouseevent
How to shrink/grow lines
painting custom components without extending jcomponent