Sandhya Java
Sandhya Java
EXP. NO:
13 DATE:
JAVAFX CONTROLS
AIM:
ALGORITHM:
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
{ launch(args);
@Override
primaryStage.setTitle("JavaFX Login
Example");
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.add(scenetitle, 0, 0, 2, 1);
grid.add(userName, 0, 1);
grid.add(userTextField, 1, 1);
Roll no: 2127220501126 Page no:
Label pw = new
Label("Password:"); grid.add(pw, 0,
2);
grid.add(passwordBox, 1, 2);
passwordTextField = passwordBox;
showPasswordCheckBox.setOnAction(event -> {
if (showPasswordCheckBox.isSelected()) {
passwordBox.setPromptText(passwordBox.getText());
passwordBox.setText("");
passwordBox.setManaged(false);
passwordBox.setVisible(false);
passwordTextField = new
TextField(passwordBox.getPromptText());
passwordTextField.setPromptText("Password");
grid.add(passwordTextField, 1, 2);
} else {
grid.getChildren().remove(passwordTextField);
passwordBox.setText(passwordTextField.getText());
passwordBox.setManaged(true);
passwordBox.setVisible(true);
Roll no: 2127220501126 Page no:
passwordTextField = passwordBox;
});
grid.add(showPasswordCheckBox, 1, 3);
hbBtn.setAlignment(Pos.CENTER);
hbBtn.getChildren().add(btn);
grid.add(hbBtn, 1, 4);
grid.add(actiontarget, 1, 6);
btn.setOnAction(e -> {
actiontarget.setText("");
String enteredPassword =
passwordTextField.getText();
if (enteredUsername.equals(username) &&
enteredPassword.equals(password)) {
actiontarget.setText("Login Successful");
actiontarget.setFill(Color.GREEN);
} else {
actiontarget.setFill(Color.RED);
});
primaryStage.setScene(scene);
primaryStage.show();
SAMPLE I/O:
RESULT:
EXP. NO:
14 DATE:
JAVAFX LAYOUTS
AIM:
ALGORITHM:
1. Create the main method and call the `launch()` method to start the JavaFX
application.
2. Implement the `start()` method to create the UI components, set up the layout,
create the `Scene`, and show the `Stage`.
3. Set up event handlers for the login and register buttons, calling the
`handleLogin()` and `handleRegistration()` methods respectively.
4. Implement the `handleLogin()` method to handle the login logic (for
simplicity, assume successful login).
5. Implement the `handleRegistration()` method to handle the registration
logic (for simplicity, assume successful registration).
6. Clear the username and password text fields after a successful registration.
7. Run the application by calling the `launch()` method in the `main()` method.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
launch(args);
@Override
// Create UI components
// Layout
new Label("Username:"),
usernameField,
new Label("Password:"),
passwordField,
loginButton,
registerButton
);
primaryStage.setScene(scene);
primaryStage.show();
// Event handlers
usernameField.clear();
passwordField.clear();
RESULT:
EXP. NO:
15 DATE:
JAVAFX MENUS
AIM:
ALGORITHM:
7. Implement the event handler for the "Enroll" button on the enrollment screen:
PROGRAM:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
launch(args);
@Override
{ this.primaryStage = primaryStage;
primaryStage.setScene(loginScene);
primaryStage.show();
dashboardLayout.getChildren().addAll(dashboardLabel, enrollButton);
enrollStudentButton.setOnAction(e -> {
});
enrollmentLayout.getChildren().addAll(enrollmentLabel, studentNameField,
enrollStudentButton);
primaryStage.setScene(enrollmentScene);