How to pass parameters to JavaFX application?

后端 未结 8 582
温柔的废话
温柔的废话 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:10

    case 1 = java standard types - transmit them as java Strings "--name=value" and then convert them to the final destination using the answer of dmolony

              for ( Map.Entry entry : namedParameters.entrySet ()){
                System.out.println (entry.getKey() + " : " + entry.getValue ());              
                switch( entry.getKey()){
                case "media_url": media_url_received = entry.getValue(); break;
                }
          }
    

    The parameter is created at Application.launch and decoded at init

    String args[] = {"--media_url=" + media_url, "--master_level=" + master_level};
    Application.launch( args);
    

    case 2 = If you have to transmit java objects use this workaround (this is for only one javafx Application launch, create a Map of workarounds and send index as strings if you have a complex case)

        public static Transfer_param javafx_tp;
    

    and in your class init set the instance of object to a static inside it's own class

        Transfer_param.javafx_tp = tp1;
    

    now you can statically find your last object for working with only one JavaFx Applications (remember that if you have a lot of JavaFx applications active you should send a String with a static variable identification inside a Map or array so you do not take a fake object address from your static structures (use the example at case 1 of this answer to transmit --javafx_id=3 ...))

提交回复
热议问题