KingAnjrey
KingAnjrey

Reputation: 35

JavaFX - Adding extra starting parameters

I worked with JavaFX because I had to programm an "interactive shell". I already programmed the Class Shell which connects to the remote host via SSH.

But the Shell has three parameters in his constructor:

public Shell(String username, String password, String host) {

    this.username = username;
    this.password = password;
    this.host     = host;
}

And what I would need (or would be perfect):

@Override
public void start(Stage primaryStage,String username, String password, String host) {
    this.primaryStage = primaryStage;
    this.shell = new Shell(username,password,host);
    initialiseOverview();
}

Is there any way I could add extra/optional starting Parameter to the JavaFX start method. Or is there any other way how I could handle this problem?

Thank you in advance :)

Upvotes: 2

Views: 71

Answers (1)

James_D
James_D

Reputation: 209704

You can access the command line parameters with Application.getParameters():

@Override
public void start(Stage primaryStage) {
    this.primaryStage = primaryStage;
    Application.Parameters parameters = getParameters();
    List<String> rawParams = parameters.getRaw();
    String userName = rawParams.get(0);
    String password = rawParams.get(1);
    String host = rawParams.get(2);
    this.shell = new Shell(username,password,host);
    initialiseOverview();
}

This code assumes there are (at least) three command line parameters. You probably want to add checks for the number of parameters and show an error message or prompt if they are missing, etc.

Upvotes: 3

Related Questions