File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Graphics without paint() method

 
Adam Wilkins
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found my answer. Disregard this post...

Thanks
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic