This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "cannot draw graphics" Watch "cannot draw graphics" New topic
Author

cannot draw graphics

Jonathan Keller
Greenhorn

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
Rancher

Joined: Sep 21, 2011
Posts: 2408
If you use Swing components (the ones named J...) you need to override paintComponent, not paint. See http://www.oracle.com/technetwork/java/painting-140037.html for details.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

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


SCJP
Visit my download page
Jonathan Keller
Greenhorn

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
Rancher

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
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
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