Reset Java Applet on page reload

自闭症网瘾萝莉.ら 提交于 2019-12-23 03:38:15

问题


I need to quit firefox and restart it in order for the applet to be refreshed... its anoying since i'm still programming it an the class files changes... am i missing some codes which makes it unable to refresh the applet and still take the one from the cache???

So I have a .jar applet in my website, a simulation game that spawns army whenever user clicks on the screen... however whenever I refresh the page, the previous army are still there on the screen.. I want it to be refreshed (as if we're just starting to run the application the first time).

I already tried pressing CTRL+f5 but the trick doesn't seem to work

I'd basically like to do it automatically using scripts or something, so that it won't require user to manually press some button on the keyboard

Any Suggestions?

I'd really appreciate it

Thank you....


回答1:


Have you tried to prevent caching?

 Pragma:no-cache
 Cache-Control:no-cache
 Expires:-1



回答2:


You are aware of the appletviewer program in the JDK?




回答3:


Try clearing the cache by Pressing Strg + Shift + Entf and then reloading the Page.




回答4:


Some understanding of the Applet lifecycle may help here.

init() is automatically called when the Applet is first loaded. This event only happens once. start() is always called just after init()
start() is automatically called whenever the user loads a page that hosts the applet.
stop() is automatically called whenever the user leaves a page that hosts the applet.
destroy() is automatically called when the applet is removed from memory. This event only happens once. stop() is always called just before destroy().

As you can tell from the description of the start() and stop() methods, the applet isn't unloaded as soon as you leave a page. I'll be honest, I'm not certain exactly when it's unloaded.

However, you could put some code in the Applet's stop() method that removes any armies that you added, or do some trickery in the start() method to reset the game data.



来源:https://stackoverflow.com/questions/2432659/reset-java-applet-on-page-reload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!