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();
}