We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Applet reloads with old information

mb2297
mb2297 asked
on
Medium Priority
219 Views
Last Modified: 2010-03-31
Hello experts,

I have a Java applet that allows users to draw onto a background. When the Applet is reloaded to use a different background, all the user's previous drawings remain and overlay the new background.

How do I get my Applet to refresh the graphics when it initializes?

Thanks,
Matt.
Comment
Watch Question

Top Expert 2006

Commented:
Clear the drawings
CERTIFIED EXPERT
Top Expert 2016

Commented:
Actually that's simple. The difficult thing is to make them stick ;-). Just make sure that no drawing takes place in the paint method at that time

Author

Commented:
Sorry, I don't quite follow you.

Is there a method I can call that clears all graphics?
Top Expert 2006
Commented:
Depends on how you store them
If they are just painted on the Canvas or an ImageBuffer
Then clear them by filling it by background color
But if they are stored as individual elements like lines and circles
So you might want to remove them to not being painted anymore

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
CERTIFIED EXPERT
Top Expert 2016

Commented:
If custom drawing is occurring, you need to flag it 'on or off'
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
As hoomanv has siad you need to clear all your stored drawing.
you can do this in the start() method of your applet.

Author

Commented:
This might be more complicated than I first thought.

What I really want to do is completely reset the Applet. No information should transfer when the Applet reloads - it should be as if I was running it for the first time. At the moment, I have some Singletons which all behave as they were before the reload.

Is there a simple way to reset everything, or do I have to build that functionality into all my classes?

Thanks,
Matt.

Author

Commented:
I have the additional problem that the panel which holds the background image gets autosized according to the image loaded into it. Once the background image is changed, the image panel does not re-adjust it's size.

Isn't there some kind of reinitialize function built in to Swing components?

Thanks,
Matt.

Author

Commented:
All the problems I was having here are explained in the accepted answer to this question: http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_22039366.html

In the end I used the destroy() method of the Applet to manually clear my drawings, and the start() method to resize the image panel.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.