Solved

Applet reloads with old information

Posted on 2006-10-22
9
200 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.
0
Comment
Question by:mb2297
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 14

Expert Comment

by:hoomanv
Comment Utility
Clear the drawings
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
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
 

Author Comment

by:mb2297
Comment Utility
Sorry, I don't quite follow you.

Is there a method I can call that clears all graphics?
0
 
LVL 14

Accepted Solution

by:
hoomanv earned 250 total points
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
If custom drawing is occurring, you need to flag it 'on or off'
0
 
LVL 92

Assisted Solution

by:objects
objects earned 250 total points
Comment Utility
As hoomanv has siad you need to clear all your stored drawing.
you can do this in the start() method of your applet.
0
 

Author Comment

by:mb2297
Comment Utility
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
 

Author Comment

by:mb2297
Comment Utility
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
 

Author Comment

by:mb2297
Comment Utility
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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now