• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

how to close and open a javafx gui multiple times the correct way..

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I'm working on a javafx simple game project which involves communicating with a server through rmi.
Data for setup will be obtain from the user through a javafx gui which will be closed and opened multiple times depending on how the setup goes.
The javafx gui's are called from the SetUp class which does not extend application itself.
After setup is complete the main game gui(javafx) will be loaded..

Assuming we have two gui's, LoginGui and OptionGui to call in that order..

Problem: call to LoginGui is successful with

Successive calls to OptionGui was not working so I was told to place the line before stage.show () in the first gui class which starts the Application process
and then in my SetUp class after the first gui which is called with "Application.launch(gui.class)" closes, other gui classes can be called with this code example


but the program just jumps this lines of code and continues without showing the OptionGui, can someone pinpoint me the correct way to do this? thanks in advance
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In general, you don't launch several applications in JavaFX, but you can use several stages.  Stages can be hidden or shown as needed.

So in your case, I would launch the a main GUI but not show the stage.  Then create a second stage that is the login window and show it.  Once the user has successfully logged on, hide the login stage and show the main stage.
 
mike Vigor
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:In general, you don't launch several applications in JavaFX, but you can use several stages.  Stages can be hidden or shown as needed.

So in your case, I would launch the a main GUI but not show the stage.  Then create a second stage that is the login window and show it.  Once the user has successfully logged on, hide the login stage and show the main stage.



ok, can you post a code snippet to launch a stage from outside the gui class? in my example from one of the SetUp class methods? a very short example of launching a first stage and closing it, and launching another one..all in another class's main or method..
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
mike Vigor
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Knute Snortum
Thanks but this is not my problem, I will love to see a snippet on how to call the gui multiple times from another class with a void main, like this for an example using your JavaFxPlay class...
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know if that is possible.  The two GUIs need to interact?  If it's a login to a server, maybe test the login first, then launch the second GUI.  Maybe the first GUI talks to the second through a socket.

I think I need to know your use case.  Normally, to log into a server, then use that connection, you would use the model I showed you.  Why do you need to launch a program, login, then go back to launching program to continue?
 
mike Vigor
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:I don't know if that is possible.  The two GUIs need to interact?  If it's a login to a server, maybe test the login first, then launch the second GUI.  Maybe the first GUI talks to the second through a socket.

I think I need to know your use case.  Normally, to log into a server, then use that connection, you would use the model I showed you.  Why do you need to launch a program, login, then go back to launching program to continue?



because the game in itself communicates to a server via rmi, so SetUp is just a controller in the middle, it gets values from the gui, then calles remote objects methods and sends data, when it gets return values or messages from the server, then it fires a gui passing the results from server as parameters, something like that...I hope you get the idea...

I know it can be  done, I just haven't figured how...
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know this topic is old but I'll leave my answer here because I might come back here sometime if you want to disable the JavaFX window and later call it again with Platform.runLater

you must set this line at the beginning of your program
platform.setImplicitExit(false);

this will cause the JavaFX thread to not exit after closing the last window and Platform.runLater will not be skipped when invoking

But if you want to call the window again it is necessary to put it in Platform.runLater
a new Stage was created


                           platform.runLater(() -> {
                               
                               Stage newStage = new Stage();
                               loginMaster = new LoginMaster(newStage, mySqlJdbcTemplate, master);
                               loginMaster.showLoginScene();
                           });
 
Marshal
Posts: 79978
397
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
PW: welcome to the Ranch
 
Bartender
Posts: 303
12
IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paweł Wodzyński wrote:I know this topic is old but I'll leave my answer here because I might come back here sometime if you want to disable the JavaFX window and later call it again with Platform.runLater

you must set this line at the beginning of your program
platform.setImplicitExit(false);

this will cause the JavaFX thread to not exit after closing the last window and Platform.runLater will not be skipped when invoking

But if you want to call the window again it is necessary to put it in Platform.runLater
a new Stage was created


                           platform.runLater(() -> {
                               
                               Stage newStage = new Stage();
                               loginMaster = new LoginMaster(newStage, mySqlJdbcTemplate, master);
                               loginMaster.showLoginScene();
                           });



This isn't the same as closing and re-creating so maybe not applicable, but if you're just hiding the UI is there a reason you don't just call hide() and show() on the primary stage? (With whatever you have in mind to trigger the stage to re-appear.)
 
Is that a spider in your hair? Here, threaten it with this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic