0% found this document useful (0 votes)
28 views1 page

Input Output

The document introduces JavaFX controls including Label, TextField, and Button. It demonstrates how to access these controls from code and handle button click events to display an alert with the text from a TextField.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views1 page

Input Output

The document introduces JavaFX controls including Label, TextField, and Button. It demonstrates how to access these controls from code and handle button click events to display an alert with the text from a TextField.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

4/26/2024

Introduction of JavaFX – Controls – Label, TextField, Button


• txtUser, txtPass, btnLogin

• Access controls from the code


• Write code in this class
package application;

import javafx.fxml.FXML;
import javafx.scene.control.TextField;

public class MyControl {


@FXML
private TextField txtUser;

public void initialize()


{
txtUser.setText("Hello");
} txtUser.getText();
}

Introduction of JavaFX – Controls – Label, TextField, Button


• txtUser, txtPass, btnLogin

• Click Login and display Alert the value in txtUser


• Need to define Event when user clicks
• Collect to the code
import javafx.scene.input.MouseEvent;
@FXML
Button btnLogin;
@FXML
private void handleClick(MouseEvent event) {
Alert alert = new Alert(AlertType.WARNING,"",ButtonType.OK);
alert.setTitle("Thông báo");
alert.setContentText("Value of txtUser is " + txtUser.getText());
alert.showAndWait();
}

You might also like