小编Mee*_*egh的帖子

JavaFx 阻止客户端多次启动应用程序

我想防止客户端多次启动应用程序。我想到了实现单例模式。

public class MyClass extends Application {

private static MyClass app = null;

private MyClass (){
    super();   
}

public static MyClass getInstance(){
    if(app == null){
    app = new MyClass();
    }
    return app; 
}

@Override
public void start(Stage primaryStage) throws Exception {
    Parent root = FXMLLoader.load(getClass().getResource("FXMLLogin.fxml"));
    Scene scene = new Scene(root);
    scene.setFill(Color.TRANSPARENT);
    primaryStage.initStyle(StageStyle.TRANSPARENT);
    primaryStage.setOpacity(0.95);
    primaryStage.setScene(scene);
    primaryStage.show();
}
public static void main(String[] args) {
    launch(args);
}
}
Run Code Online (Sandbox Code Playgroud)

但是,当我运行该应用程序时,出现错误:

 Exception in Application constructor
 java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) …
Run Code Online (Sandbox Code Playgroud)

java singleton javafx javafx-11

1
推荐指数
1
解决办法
288
查看次数

标签 统计

java ×1

javafx ×1

javafx-11 ×1

singleton ×1