How to pass parameters to JavaFX application?

后端 未结 8 556
温柔的废话
温柔的废话 2020-11-28 13:49

I am running my JavaFX application like this:

public class MainEntry {
    public static void main(String[] args) {
        Controller controller = new Contr         


        
8条回答
  •  借酒劲吻你
    2020-11-28 14:05

    Of course there is a need and possibility to pass parameters to JavaFX application.

    I did it to run my JavaFX client from different places, where different network configurations are required (direct or via proxy). Not to make instant changes in code, I implemented several network configurations to be chosen from in application run command with parameter like --configurationIndex=1. The default code value is 0.

    List parameters;
    int parameterIndex;
    String parameter;
    
    parameters =
      getParameters().getRaw();
    
    for (parameterIndex = 0;
      parameterIndex < parameters.size();
      parameterIndex++) {
    
      parameter =
        parameters.get(
          parameterIndex);
    
      if (parameter.contains("configurationIndex")) {
        configurationIndex =
          Integer.valueOf(
            parameters.get(parameterIndex).
            split("=")[1]);
      }
    }
    

    In Netbeans you can set this parameter for debugging need directly on your project: Project - Properties - Run - Parameters - insert --configurationIndex=1 into field.

提交回复
热议问题