Skip to content
Advertisement

Get Current logged User Id and User Name using JavaFX

I’m trying to create an application using JavaFX. I want to get current logged userid and username, after successful login. I want to display it is in the home page. How can i do this? please help

MediaController.java

JavaScript

Advertisement

Answer

Let me get this straight, you have the user login, then change the scene to a main window, but you want to remember the user that logged in and display that username on the homepage?

Sounds like you will have to pass data between scenes.

For that you will need to approach this in OOP. Have a object class representing your user with all the getters and setters.

JavaScript

When you connect to the database at login, validate user then instantiate an object of the “User” class for example, then pass it to the mainwindow scene your are loading.

JavaScript

}

Have a “initData” class or something in the mainwindowcontroller.

Like

JavaScript

Then from your login class, upon validation, send the data to the mainwindow before changing your scene by instantiating your User, then passing the object to the initData method from your second scene.

JavaScript

Then upoin login, use the changeToMainWindow() method and it’ll pass the user.

In the above example I am simply passing email, but you get the point.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement