2013-10-04 88 views
0

目前我正在JavaFX 2上开发GUI,并且我发现了很好的oracle示例:FXML-LoginDemo。在此示例中的场景2(FXML系),第一是AuthoriseForm,第二是的UserData变化的,主要类具有下一个方法:方法如何调用?

public boolean userLogging(String userId, String password){ 
    if (Authenticator.validate(userId, password)) { 
     loggedUser = User.of(userId); 
     gotoProfile(); 
     return true; 
    } else { 
     return false; 
    } 
} 

gotoProfile(); - 变化的场景..

的LoginController类具有下一个方法:

public void processLogin(ActionEvent event) { 
     if (application == null){ 
      // We are running in isolated FXML, possibly in Scene Builder. 
      // NO-OP. 
      errorMessage.setText("Hello " + userId.getText()); 
     } else { 
      if (!application.userLogging(userId.getText(), password.getText())){ 
       errorMessage.setText("Username/Password is incorrect"); 
      } 
     } 
    } 

processLogin()在代码中没有电话..所以,问题是:如何processLogin()来电按下

回答

0

这里是Login.fxml文件的链接。

该文件包含这一行:

<Button id="button1" fx:id="login" defaultButton="true" onAction="#processLogin" prefHeight="70.0" prefWidth="400.0" text="Login" AnchorPane.bottomAnchor="66.0" AnchorPane.leftAnchor="40.0" AnchorPane.rightAnchor="40.0" /> 

这行设置该属性:

onAction="#processLogin" 

该属性表示,按一下按钮(动作事件)应该是handled by a method defined in the controller

+0

太棒了!非常感谢! –