2017-05-22 2 views
0

J'ai un formulaire de connexion créé en JavaFX et après une connexion réussie, il doit être caché, Je suis le code qui a servi à cacher le formulaire après la connexion réussie de cette vidéo, mais ne fonctionne pas pour moi https://www.youtube.com/watch?v=DeK9DfXG5Tg fondamentalement c'est le code ((Node)(event.getSource())).getScene().getWindow().hide();Impossible de masquer mon formulaire de connexion après la connexion réussie

le problème que je ne reçois aucune erreur pour savoir quel est le problème?

c'est mai Main classe

public class Main extends Application { 
    @Override 
    public void start(Stage primaryStage) { 
     try { 
      BorderPane root = 
    (BorderPane)FXMLLoader.load(getClass().getResource("/fx/Login.fxml")); 
      Scene scene = new Scene(root,310,180);  
    scene.getStylesheets(). 
     add(getClass().getResource("application.css").toExternalForm()); 
      primaryStage.setScene(scene); 
      primaryStage.show(); 
     } catch(Exception e) { 
      e.printStackTrace(); 
     } 
    } 

    public static void main(String[] args) { 
     launch(args); 

    } 
} 

ma classe contrôleur

public class LoginController { 

    @FXML 
    private TextField Usernamefield; 

    @FXML 
    private PasswordField Passwordfield; 

    @FXML 
    public void LoginButtonHandler(ActionEvent event){ 

     String UserName = Usernamefield.getText().trim(); 
     String PassWord = Passwordfield.getText().trim(); 
     Session session = 
     HibernateUtil.getSessionFactory().getCurrentSession(); 
     try { 
      session.beginTransaction(); 
      String hql =" from User where Username=:UserName and Password=:PassWord"; 
      Query query = session.createQuery(hql); 
      query.setParameter("UserName",UserName); 
      query.setParameter("PassWord",PassWord); 
      List ResultSet = query.getResultList(); 

      if (ResultSet.size()==1){ 

       SessionInfo sessioninfo = new SessionInfo(); 
       sessioninfo.setUsername(UserName); 
       System.out.println("welcome "+ sessioninfo.getUsername()); 
       System.out.println("opening dashboard"); 
       /***************************************************** 
       * openining dashboard after user logged successfully* 
       *****************************************************/ 
       try{ 

       ((Node)(event.getSource())).getScene().getWindow().hide(); 
        FXMLLoader fxmlLoader = new 
        FXMLLoader(getClass().getResource("DashBoard.fxml")); 
        BorderPane root = (BorderPane) fxmlLoader.load(); 
        Stage stage = new Stage(); 
        //stage.initModality(Modality.APPLICATION_MODAL); 
        //stage.initStyle(StageStyle.UNDECORATED); 
        stage.setTitle("Welcome "+sessioninfo.getUsername()); 
        stage.setScene(new Scene(root)); 
        stage.show(); 
        } catch(Exception e) { 
         e.printStackTrace(); 
         } 


      }else 
       { 
       System.out.println("login faild"); 
      } 
      System.out.println("current session statics"+session.getStatistics()); 
      System.out.println(Usernamefield.getText()); 
      System.out.println(Passwordfield.getText()); 
      System.out.println("transaction status 
      :"+session.getTransaction().getStatus()); 
      System.out.println("result size is :"+ResultSet.size()); 


     } 
     catch (HibernateException e) { 
      if (session.getTransaction() != null) { 
       session.getTransaction().rollback(); 
       e.printStackTrace(); 
      } 
     } 
     finally { 
      session.close(); 
      System.out.println("session is closed"); 
     } 


    } 
} 

mon FXML

<BorderPane xmlns="http://javafx.com/javafx/8.0.111" 
xmlns:fx="http://javafx.com/fxml/1" 
fx:controller="fx.LoginController"> 
    <center> 
     <GridPane minHeight="172.0" minWidth="300.0" prefHeight="172.0" 
    prefWidth="326.0" BorderPane.alignment="CENTER"> 
     <columnConstraints> 
      <ColumnConstraints hgrow="SOMETIMES" maxWidth="228.0" 
    minWidth="10.0" prefWidth="65.0" /> 
      <ColumnConstraints hgrow="SOMETIMES" maxWidth="406.0" 
    minWidth="100.0" prefWidth="261.0" /> 
     </columnConstraints> 
     <rowConstraints> 
      <RowConstraints minHeight="10.0" prefHeight="30.0" 
    vgrow="SOMETIMES" /> 
      <RowConstraints minHeight="10.0" prefHeight="30.0" 
    vgrow="SOMETIMES" /> 
      <RowConstraints minHeight="10.0" prefHeight="30.0" 
    vgrow="SOMETIMES" /> 
     </rowConstraints> 
     <children> 
     <ImageView fitHeight="40.0" fitWidth="40.0" pickOnBounds="true" 
     preserveRatio="true"> 
       <image> 
        <Image url="@../../resource/images/User-40.png" /> 
       </image> 
       <GridPane.margin> 
        <Insets left="10.0" /> 
       </GridPane.margin> 
      </ImageView> 
      <ImageView fitHeight="150.0" fitWidth="40.0" 
     pickOnBounds="true" preserveRatio="true" GridPane.rowIndex="1"> 
       <image> 
        <Image url="@../../resource/images/Lock-40.png" /> 
       </image> 
       <GridPane.margin> 
        <Insets left="10.0" /> 
       </GridPane.margin> 
      </ImageView> 
      <PasswordField fx:id="Password" promptText="password" 
     GridPane.columnIndex="1" GridPane.rowIndex="1"> 
       <GridPane.margin> 
        <Insets left="10.0" right="10.0" top="10.0" /> 
       </GridPane.margin> 
      </PasswordField> 
      <Button mnemonicParsing="false" onAction="#Login" text="Login" 
     GridPane.columnIndex="1" GridPane.rowIndex="2"> 
       <GridPane.margin> 
        <Insets left="190.0" /> 
       </GridPane.margin> 
      </Button> 
      <TextField fx:id="Username" promptText="username" 
     GridPane.columnIndex="1"> 
       <GridPane.margin> 
        <Insets left="10.0" right="10.0" /> 
       </GridPane.margin></TextField> 
     </children> 

      <BorderPane.margin> 
      <Insets /> 
     </BorderPane.margin> 
     <opaqueInsets> 
      <Insets /> 
     </opaqueInsets> 
      </GridPane> 
     </center> 
     <top> 
      <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Air Book" 
      BorderPane.alignment="CENTER" /> 
      </top> 
</BorderPane> 

Répondre

2

Vous devez spécifier le nom de la méthode de conrrect pour le gestionnaire dans le FXML. Etant donné que le nom de la méthode est LoginButtonHandler, la valeur correcte pour l'attribut onAction de l'élément <Button> est #LoginButtonHandler:

<Button mnemonicParsing="false" 
     onAction="#LoginButtonHandler" 
     text="Login" 
     GridPane.columnIndex="1" 
     GridPane.rowIndex="2"> 
    <GridPane.margin> 
     <Insets left="190.0" /> 
    </GridPane.margin> 
</Button>