title: JavaFX : invoking ' Application.launch(args) ' from a method other than main
body: <p><strong>Question</strong></p>
  
  <p>Can I call ' Application.launch(args); ' from a method other than main?  If so could you provide an example keeping in mind the below context?</p>
  
  <p><strong>Background</strong></p>
  
  <p>I'm build a learning/teaching, command/text application, that teaches the user about arrays.  At the end of the main class, after the major application content has ran, I call ' ViewSiteOrExit.viewSitePromptPuSVM(); ', which gives the user the opposition to either: open the Oracle page on arrays, or exit the game.</p>
  
  <p>If the user wishes to view the Oracle page I invoke ' OpenSite.??????????(); ', which will open the page in an FX VBox.  If not, exit.</p>
  
  <p>This is the first time I've ever used FX, and I'm tired, so any observations and suggestion, of and for, my code would really help, because I may be missing something.</p>
  
  <p>But my main question is how can/should I call ' OpenSite.??????????(); ', the method containing 'Application.launch(args);, if not from my main?</p>
  
  <p>If it must be called from main, how can I do so, only after the primary parts of the app has ran, and only if the user has input ' y '?</p>
  
  <p>Below is the .java that prompts the user to view the site or exit the game, and the .jave that opens the page.</p>
  
  <pre><code>package mrArray;
  
  import javafx.application.Application;
  import javafx.geometry.Insets;
  import javafx.geometry.Pos;
  import javafx.scene.Scene;
  import javafx.scene.layout.VBox;
  import javafx.scene.web.WebEngine;
  import javafx.scene.web.WebView;
  import javafx.stage.Stage;
  
  public class OpenSite extends Application 
  {
      VBox vBoxOF = new VBox();
  
    public static void main(String[] args) 
    {
      Application.launch(args);
    }
  
    @Override
    public void start(Stage primaryStage) 
    {
      vBoxOF.setId("root");
  
      WebView  webViewBrowserOL = new WebView();
      WebEngine webEngineOL = webViewBrowserOL.getEngine();
      String urlSL = "http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html";
      webEngineOL.load(urlSL);
  
      vBoxOF.setPadding(new Insets(30, 50, 50, 50));
      vBoxOF.setSpacing(10);
      vBoxOF.setAlignment(Pos.CENTER);
      vBoxOF.getChildren().addAll(webViewBrowserOL);
  
      Scene sceneOL = new Scene(vBoxOF);
      primaryStage.setScene(sceneOL);
      primaryStage.show();
    }
  }
  </code></pre>
  
  <p><strong>Second Class</strong></p>
  
  <pre><code>package mrArray;
  
  
  public class ViewSiteOrExit 
  {
      /*
       * declare fields,
       */
      private static int statePrSIF;
      private static String enterYOrNPrSSOF;
  
      /*
       * declare method,
       * initialize field,
       * while, test(field) is passing execute,
       * switch, evaluates cases with value(field),
       * matching, execute statements,
       * 0, first case, prompt, y drop to if, reset value, use app again,
       * n drop to else, increment field, 1, second case,
       * invoke method to close app, reset field value to prevent double field invocation,
       * return flow to caller to prevent use of closing Scanner,
       */
       public static void viewSitePromptPuSVM() 
       {
           statePrSIF = 0;
           while (statePrSIF &lt; 2) 
           {
               switch (statePrSIF) 
               {
                  case 0: 
                      System.out.println();
                      System.out.println("[:-)] One more question?");
                      System.out.println("Would you like to see what Oracle has to say about me?");
                      System.out.println("Enter ' y ' for yes.");
                      System.out.println("Enter ' n ' for no.");
                      break;
                  case 1:
                      goodByePuSVM();
                      statePrSIF = 0;
                      return;
               }
  
               enterYOrNPrSSOF = MrArray.scannerOF.next();
  
               if(enterYOrNPrSSOF.equalsIgnoreCase("y")) 
               {
                   statePrSIF = 0;
                   System.out.println("[:-)] Well bud, it's been fun.");
                   System.out.println("Here is that Orcale thing.");
                   System.out.println("See ya later!");
                   OpenSite.??????????();
               }
               else if(enterYOrNPrSSOF.equalsIgnoreCase("n")) 
               {
                   statePrSIF++;
               }  
           }
       }
  
       /*
        * declare method,
        * invoke methods, display output,
        * close Scanner, terminate,
        */
       public static void goodByePuSVM()
       {
              System.out.println("[:-)] Well bud, it's been fun.");
              System.out.println("See ya later!");
  
              MrArray.scannerOF.close();
       }
  }
  </code></pre>