• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • Last Modified:

Applet reloads with old information

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.
0
mb2297
Asked:
mb2297
  • 4
  • 2
  • 2
  • +1
2 Solutions
 
hoomanvCommented:
Clear the drawings
0
 
CEHJCommented:
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
0
 
mb2297Author Commented:
Sorry, I don't quite follow you.

Is there a method I can call that clears all graphics?
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
hoomanvCommented:
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
0
 
CEHJCommented:
If custom drawing is occurring, you need to flag it 'on or off'
0
 
objectsCommented:
As hoomanv has siad you need to clear all your stored drawing.
you can do this in the start() method of your applet.
0
 
mb2297Author 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.
0
 
mb2297Author 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.
0
 
mb2297Author 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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now