Reputation: 5444
I want somewhere down in the java code:
if(inAnApplet()) {
initForApplet();
} else {
initForApp();
}
Upvotes: 0
Views: 204
Reputation: 3682
Like jli said, maybe you could create initialise a public (static) boolean isApplet = true
somewhere accessible in the class in which you would like to do the check and set that to false in your main method, as public static void main(String[] args)
is not called in an Applet.
This way your check would simply start if(isApplet)
!
HTH
Upvotes: 1
Reputation: 2975
public class MyApplet extends JApplet {
boolean isapplet = true;
public MyApplet() {
this(true);
}
public MyApplet(boolean isapplet) {
this.isapplet = isapplet;
}
public static final void main(String[] argv) {
// is an app
new MyApplet(false);
}
}
Upvotes: 5
Reputation: 62439
Assuming that somewhere you have a view which extends JApplet
and it is accessible from the code where you have the if, you can write:
if(mainView instanceof JApplet) {
initForApplet();
} else {
initForApp();
}
Upvotes: 2