How to find out if my program works as an applet or as a Java application

I wrote a clumsy little breakout clown, and I write to disk to save games and high scores.

Is there an easy way to check if my program works as an applet or as an application?

eg,...

if(!anApplet){
//Include disk i/o features
}

I tried to set a boolean in the "main" class, setting it to false with init () and true in the main method, but so far no luck. Will you continue to try, but thanks in advance for any advice!

+5
source share
1 answer

Use AccessController . You can wrap all calls in a block AccessController.doPrivileged.

AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            // privileged code goes here, for example, read and writing files.
            ...
            return null; // nothing to return
        }
});

, , , , :

Boolean flag = AccessController.doPrivileged(new PrivilegedAction() {
        public Boolean run() {
            boolean flag = false;
            // privileged code goes here, for example, read and writing files. If it succeeds, set flag to true.
            ...
            return flag; // return true, if the privileged action succeeded
        }
});

. , ; " " , .

AccessControlException s, . , , , false. AccessController.doPrivilege .

# 2

AccessController.checkPermission , . , , .

+3

All Articles