*
The moose likes Swing / AWT / SWT and the fly likes Graphics without paint() method 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 "Graphics without paint() method" Watch "Graphics without paint() method" New topic
Author

Graphics without paint() method

Adam Wilkins
Greenhorn

Joined: Oct 19, 2005
Posts: 24
I have a mortgage calculation application (not applet) that is all set up with a JFrame, JPanels, and all other JCompenents. Now, I would like to display graphics within this JFrame. From my main method, I call the instance method of my class to create the window, buttons, fields, etc and add actionListener(s) to my buttons. Now, I only know how to add graphics with the paint() method, but if I move my window creation code to my paint() method and subsequently end it with repaint(), the results are unacceptable with every refresh.

If I keep my instance method in their to create the window and try to add a paint method for the graphics only, it overrides my complete window.

Is there a way to add graphics and animation to a JFrame without using the paint() method?

Thanks in advance....
Adam Wilkins
Greenhorn

Joined: Oct 19, 2005
Posts: 24
I found my answer. Disregard this post...

Thanks
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
For the sake of other posters ... if you want to display some graphics,
never override paint in JFrame, JApplet, etc... Instead, subclass JComponent
or JPanel and override its paintComponent method:

Create an instance of your class and add that component to your UI, like
any other component.
Here is the 2D graphics tutorial: http://java.sun.com/docs/books/tutorial/2d/index.html


There is no emoticon for what I am feeling!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Graphics without paint() method
 
Similar Threads
Graphics coordinates problem
Calling the repaint() method
Printing Solved but?
HYPERLINKING FROM APPLETS
How can I get the feature ALWAYS_ON_TOP with the swing JFrames.