java - JavaFX: How to ask for user input before a GUI is displayed -


i'm having little bit of trouble javafx in netbeans 7.3.1. i'm attempting make game rolls die. program supposed ask user if die fair or not, along other information (such number of sides) initialize die roll. when roll button clicked, roll die.

my issue since javafx ignores main program when launches gui, i'm not sure (or how) ask user information before gui loads.

public class dicegame extends application {  @override public void start(stage primarystage) {     button btn = new button();     btn.settext("roll die!");     btn.setonaction(new eventhandler<actionevent>() {         @override         public void handle(actionevent event) {             //              // code rolling die goes here.         }     });      stackpane root = new stackpane();     root.getchildren().add(btn);      scene scene = new scene(root, 300, 250);      primarystage.settitle("dice game");     primarystage.setscene(scene);     primarystage.show(); }  /**  * main() method ignored in correctly deployed javafx application.  * main() serves fallback in case application can not  * launched through deployment artifacts, e.g., in ides limited fx  * support. netbeans ignores main().  *  * @param args command line arguments  */   public static void main(string[] args) {      //ask user n value initialize die object before javafx ui launched.      system.out.println("is die loaded or fair? *input 1 fair , 2 loaded* ");      scanner fair_or_loaded = new scanner(system.in); //determines fair or loaded die.     int input = fair_or_loaded.nextint();      if (input == 1) {         system.out.println("input n value fair die: ");         scanner user_input = new scanner(system.in); //created fair die.         int n = user_input.nextint();         die d1 = new die(n); //user created die.      } else { //loaded die created. need scanner loadedside , loadfactor.         system.out.println("input n value loaded die: ");         scanner loaded_n_input = new scanner(system.in);         int loaded_n = loaded_n_input.nextint(); //loaded n value created          system.out.println("input side loaded: ");         scanner user_side = new scanner(system.in);         int side_loaded = user_side.nextint(); //loaded side created          system.out.println("input load factor: ");         scanner user_load = new scanner(system.in);         int factor_load = user_load.nextint(); //load factor created          loadeddie dl = new loadeddie(loaded_n, side_loaded, factor_load); //loaded die created.     }       launch(args);     } } 

thanks in advance!

as said in comment in code, javafx applications, when launched properly, don't use main() method traditional java applications - create instance of default application class , call start method.

so if want code execute before gui shown, you'll have call @ beginning of start method. preferably, put corresponding code in separate method call method before start building ui.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -