• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Graphics without paint() method

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found my answer. Disregard this post...

Thanks
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic