Advertisement
pastebin46545

situation_handwritten.java

Sep 28th, 2017
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.97 KB | None | 0 0
  1.    
  2.     /**
  3.      The task:
  4.       - FX-Windows is running (main stage)
  5.       - User should enter a new password in a stage (pw stage)
  6.       - after entering the password, the main stage should go on
  7.      
  8.      The Problem:
  9.       - main stage does not wait, goes on before password is entered
  10.      
  11.      The solutions:
  12.       - two like as following
  13.      
  14.      Problem:
  15.       - Solution 1 needs much modifications in the code
  16.       - Solution 2 does not work for JavaFX (Thread is no FX-Thread)
  17.      
  18.      Question:
  19.       - easy solution for FX?
  20.      
  21.      
  22.       SEE IMPLEMENTATION at "simpleDemo" folder, but no FX
  23.     */
  24.    
  25.    
  26.     /**
  27.         ONLY PSEUDO CODE !!!
  28.     */
  29.  
  30.     public static char[] getPassword(String message) {
  31.         run = true;
  32.         showWindow(message);   // JFrame or FX-Window
  33.        
  34.         // while (run);  // infinite loop, gui hangs, so no solution
  35.         run = false;
  36.  
  37.         // Working on the insert data of "password1"
  38.         if (pwMatches()) {
  39.             return password1;
  40.         } else {
  41.             return null;
  42.         }
  43.     }
  44.    
  45.     /*
  46.         First Solution (FX):
  47.     */
  48.  
  49.     public static void getPassword(String message) {
  50.         run = true;
  51.         showWindow(message,    // JFrame or FX-Window
  52.        
  53.             //    Function<char[],Void>
  54.             password -> {
  55.  
  56.             // Working on the insert data in "password"
  57.             if (pwMatches()) {
  58.                 Manager.setPassword(password1);
  59.             } else {
  60.                 System.exit(0);
  61.             }
  62.            
  63.             // POSITION 1
  64.             return null;
  65.         });
  66.        
  67.         // HERE MUST BE NOTHING! MUST ALL AT POSITION 1
  68.     }
  69.    
  70.     /*
  71.         Secound Solution (FX):
  72.     */
  73.  
  74.     public static void getPassword(String message) {
  75.        
  76.         Thread t = new Thread(new RunableTemp(message);
  77.         t.start();
  78.        
  79.         // Waiting till the user inserted the data to "password1"
  80.         while(t.isAlive())
  81.         {
  82.             Thread.sleep(1000);
  83.         }
  84.        
  85.          if (pwMatches()) {
  86.             return password1;
  87.         } else {
  88.             return null;
  89.         }
  90.     }
  91.    
  92.     class RunableTemp implements Runable{
  93.    
  94.         ... void run()
  95.         {
  96.             showWindow(message);
  97.         }
  98.    
  99.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement