• 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

Converting an applet to a Panel on a frame

 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having trouble converting a Sun sample from a perfectly working Clock applet to a Clock on a Panel on a JFrame. I thought it would be a simple task, but it seems to be more of a headache that I thought! This is just a Sun sample that I am trying to convert:
working applet:

my feeble attempt

I'm not sure if this is a threading issue or a Swing issue


thanks,

Jamie
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not going to go through all that code, especially considering the lack of a description of the results you're getting, but I can make an observation that may help: An application does not use a Graphics context in the same way that an applet does. Remember, an applet runs within the context of the browser, while an application runs in its own (Swing) or using o/s resources (AWT).

Also, applets have methods that are automatically called at various stages of their existence. The same is not true of an application; you must explicitly call methods in an application.

Good luck!
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Most of the time, it's pretty easy to turn an applet into an application. You can just say



This works as long as the applet doesn't try to use its AppletStub or AppletContext, which will be null here. The only problem methods like that that I see here are the getParameter() calls, which might have to be changed (although maybe not; things seem to be written nicely so that they default gracefully on null.)

Anyway, I gave this a try, and it works perfectly for me.
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jeff Bosch:
I'm not going to go through all that code, especially considering the lack of a description of the results you're getting, but I can make an observation that may help: An application does not use a Graphics context in the same way that an applet does. Remember, an applet runs within the context of the browser, while an application runs in its own (Swing) or using o/s resources (AWT).

Also, applets have methods that are automatically called at various stages of their existence. The same is not true of an application; you must explicitly call methods in an application.

Good luck!



Leave it to a bartender to post a load of code with little description! In my feeble attempt, I was getting some null pointer exceptions and the frame/panel/clock was not being properly painted. But really, It was more about converting the working applet than fixing my code. I just posted my attempt to show my attempt. Anyways, it looks as though I was missing a call to super.paintComponent( g ). I'll have to comb through the code to see if there is anything else I was missing. Thanks for your help Craig and everyone else.

One last question, does an applet not need to have its paint methods explicitly called?

thanks, Jamie
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can call an Applets paint method if you like. It isn't necessary to call it unless you want to do some custom painting in the Applet. It will paint over all child components. In the AWT we often override the update method; but usually not in Swing.
 
Grow a forest with seedballs and this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic