[英]Best way to detect whether code is running in an application server java
[英]what is the best way to test whether java code is running in an applet or not?
我想要在Java代碼中的某個地方:
if(inAnApplet()) {
initForApplet();
} else {
initForApp();
}
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);
}
}
假設您在某個地方有一個擴展JApplet
的視圖,並且可以從擁有if的代碼中訪問它,則可以編寫:
if(mainView instanceof JApplet) {
initForApplet();
} else {
initForApp();
}
就像jli所說的那樣,也許您可以在類要訪問的某個地方創建一個初始化的public (static) boolean isApplet = true
,並在您的main方法中將其設置為false,如public static void main(String[] args)
在Applet中未調用。
這樣,您的支票就可以簡單地從if(isApplet)
開始!
高溫超導
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.