From the course: Learning NetBeans
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Add code to handle an event
- [Instructor] So we're ready to make the button to display the text message when the user presses it, and we do that with this code here, starting on line 71. Now, right below 71, you'll see we use setOnAction, and that method is used to register an event handler that sets the action target object to assign in button pressed when the user presses the button. The color of the action target object is set to fire brick red. So now the moment of truth. Let's go ahead and test our application by executing it. And here we go. Let's do this. So we can put in a user name and a fake password, or a real one, if you choose, and let's click Sign in to evoke our event, and it does evoke it, and it says Sign in button was pressed, just as we expected. So this is nice. The UI looks fairly clean, and if we decided to try to resize it, the positions based on how we coded it stays nice and centered. And that's one of the benefits of JavaFX, and that's why I prefer it for desktop applications.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.