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


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply 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: 2407
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
    
    1
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
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cannot draw graphics
 
Similar Threads
Mousedragging not working after updating the array.
Messagebox with Mouseevent
Applet help
How to shrink/grow lines
painting custom components without extending jcomponent