Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- The task:
- - FX-Windows is running (main stage)
- - User should enter a new password in a stage (pw stage)
- - after entering the password, the main stage should go on
- The Problem:
- - main stage does not wait, goes on before password is entered
- The solutions:
- - two like as following
- Problem:
- - Solution 1 needs much modifications in the code
- - Solution 2 does not work for JavaFX (Thread is no FX-Thread)
- Question:
- - easy solution for FX?
- SEE IMPLEMENTATION at "simpleDemo" folder, but no FX
- */
- /**
- ONLY PSEUDO CODE !!!
- */
- public static char[] getPassword(String message) {
- run = true;
- showWindow(message); // JFrame or FX-Window
- // while (run); // infinite loop, gui hangs, so no solution
- run = false;
- // Working on the insert data of "password1"
- if (pwMatches()) {
- return password1;
- } else {
- return null;
- }
- }
- /*
- First Solution (FX):
- */
- public static void getPassword(String message) {
- run = true;
- showWindow(message, // JFrame or FX-Window
- // Function<char[],Void>
- password -> {
- // Working on the insert data in "password"
- if (pwMatches()) {
- Manager.setPassword(password1);
- } else {
- System.exit(0);
- }
- // POSITION 1
- return null;
- });
- // HERE MUST BE NOTHING! MUST ALL AT POSITION 1
- }
- /*
- Secound Solution (FX):
- */
- public static void getPassword(String message) {
- Thread t = new Thread(new RunableTemp(message);
- t.start();
- // Waiting till the user inserted the data to "password1"
- while(t.isAlive())
- {
- Thread.sleep(1000);
- }
- if (pwMatches()) {
- return password1;
- } else {
- return null;
- }
- }
- class RunableTemp implements Runable{
- ... void run()
- {
- showWindow(message);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement