aspose file tools*
The moose likes Applets and the fly likes Auto Exit the AppletViewer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Auto Exit the AppletViewer" Watch "Auto Exit the AppletViewer" New topic
Author

Auto Exit the AppletViewer

Koh Khai Huat
Ranch Hand

Joined: Aug 05, 2005
Posts: 100
Hi Guys,

I got a game running on a appletviewer. and i would like the applet to exit by it self when the game finish. I would like to ask if any of u guys know any method or command that i can invoke in the java code to exit the applet. Please let me know thanks in advance

regards
KKH


if (!WorkHard){
System.out.println("Fail!!!");
}
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Take in mind that an applet typically is displayed inside a HTML page. What would it mean for an applet "to exit" in that context?

Moving to our Applet forum...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42591
    
  65
The System.exit call will quit the appletviewer, like it does with any other Java application. After all, the appletviewer is (for the most part) just another Java application.


Ping & DNS - my free Android networking tools app
Koh Khai Huat
Ranch Hand

Joined: Aug 05, 2005
Posts: 100
Hi Ulf Dittmer,

Thanks For Yr Post but when i call System.exit(0); the program game me this exception => "java.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM)"

Do u know why this exception is thrown and how to get the access to exit my appletViewer?

Many Thanks In Advance

regards
KKH
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42591
    
  65
Ah! appletviewer actually enforces the applet security restrictions - that wasn't always the case. Create a file (say, 'applet.policy') containing the following in your applet directory:


If you then run the appletviewer by

appletviewer -J-Djava.security.policy=applet.policy applet.html

it will use the file as security policy file. What that does is to allow the applet to call System.exit. There's more information about how this works in the FAQ: HowCanAnAppletReadFilesOnTheLocalFileSystem.

By the way, please don't use abbreviations like "u" and "yr" in your posts. They're OK for text messaging, but in a forum like this, where many people do not speak English as a native language, and have a hard enough time following what's being said as it is, they're not appropriate.
[ March 16, 2006: Message edited by: Ulf Dittmer ]
Koh Khai Huat
Ranch Hand

Joined: Aug 05, 2005
Posts: 100
hi Ulf Dittmer,

Thanks for your comment and it help me alot Thanks. As for the "yr" and "u" I apologize for that and will try my best not to make that mistake again

best regards,
KKH
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Auto Exit the AppletViewer