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: 2407
posted Dec 01, 2011 10:36:25
0
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: 4092
tim is correct.
thanks jonathan for showing me how to tell which button was clicked.
SCJP
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: 2407
posted Dec 01, 2011 23:49:07
0
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: 19216
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
How To Ask Questions How To Answer Questions
subject: cannot draw graphics