views:

31

answers:

1

My aim is to create a small javafx application that makes use of javafx forms (handled by separate java classes) for example: Login.fx (GUI) calls methods from LoginFunc.java. to handle user interactions.

My problem is that I need to pass the username and password entered by the user to LoginFunc. Usually in swing applications i use a constructor such as

public LoginFunc (String username, String password) { }

How can I call such a class from a javafx file? my current code is:

function btnLoginAction(): Void { var username: String; var password: String; var login: LoginFunc;

    username = txtUsername.text;
    password = txtPassword.text;

}

Any help is appreciated!

A: 

If I understand your question correctly, I think you want to add this to Login.fx:

def loginButton = Button {
    action: btnLoginAction
}
function btnLoginAction(MouseEvent:e):Void {
    var username = txtUsername.text;
    var password = txtPassword.text;
    // construct new LoginFunc note the CURLY braces
    var login:LoginFunc = LoginFunc{};
    login.doSomething(username, password);
}

If I misinterpreted, please let me know.

Eric Wendelin
Hi Eric! that's it! Thanks to you I've managed to pass 2 string vars to the constructor method of LoginFunc. lol, I'm used to regular Java code but I haven't managed to understand JavaFX script yet.I am trying to redevelop my swing electronic patient record system in javafx (mainly for educational purposes). I believe that JavaFX will be the next Swing in java user interfaces.I have one other question. It seems that whenever I click the login button, the function is executed but when I use the keyboard (using tabs and "click" using the spacebar the function is not executed)
spiksander
The following is my current codefunction btnLoginOnMouseClicked(event: javafx.scene.input.MouseEvent): Void { var username = txtUsername.text; var password = txtPassword.text; var login:LoginFunc = new LoginFunc(username, password); login.printDetails(); }Do I need to create a separate function for every possible event? Please note that I am currently using Netbeans 6.9 with the JavaFX designer (I'm considering going back to basics and forget about the designer mainly to learn how it works behind the scenes)I apologize for the long post :(Thanks!
spiksander
No, you can certainly reuse functions for different events, as long as the arguments are compatible. Glad it's working for you :)
Eric Wendelin