This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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: 4340

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: 19651

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
wood burning stoves
subject: cannot draw graphics
Similar Threads
Messagebox with Mouseevent
How to shrink/grow lines
Mousedragging not working after updating the array.
painting custom components without extending jcomponent
Applet help