CS22409 – JAVA PROGRAMMING: THEORY AND PRACTICES
EXP. NO:
13 DATE:
JAVAFX CONTROLS
AIM:
To write a Java program to develop Student management application using
JavaFX controls
ALGORITHM:
1. Create the main method
- The `main()` method is the entry point of the application.
- It calls the `launch()` method to start the JavaFX application.
2. Implement the `start()` method
- The `start()` method is the main entry point for the JavaFX application.
- It creates the UI components, such as buttons, text fields, and labels.
- It sets up the layout using a `VBox` and adds the UI components to it.
- It creates a `Scene` object with the layout and sets it on the `Stage`.
- It sets the title of the `Stage` and shows it.
3. Set up event handlers
- The `setOnAction()` method is used to attach event handlers to the
login and register buttons.
- The `handleLogin()` method is called when the login button is clicked.
Roll no: 2127220501126 Page no:
- The `handleRegistration()` method is called when the register button is
clicked.
4. Implement the `handleLogin()` method
- This method takes the username and password entered by the user.
- For simplicity, it assumes a successful login and prints a message to
the console.
- In a real application, this method would implement the actual login
logic, such as checking the credentials against a database.
5. Implement the `handleRegistration()` method
- This method takes the username and password text fields as parameters.
- For simplicity, it assumes a successful registration and prints a
message to the console.
- In a real application, this method would implement the actual
registration logic, such as adding the new user to a database.
6. Clear the text fields after registration
- After a successful registration, the method clears the username
and password text fields.
7. Step 7: Run the application
- The `launch()` method in the `main()` method starts the
JavaFX application.
- The `start()` method is called, and the application window is displayed.
Roll no: 2127220501126 Page no:
PROGRAM:
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class exp13 extends Application {
private String username = "admin";
private String password = "admin";
private TextField passwordTextField;
private TextField userTextField;
Roll no: 2127220501126 Page no:
public static void main(String[] args)
{ launch(args);
@Override
public void start(Stage primaryStage) {
[Link]("JavaFX Login
Example");
GridPane grid = new GridPane();
[Link]([Link]);
[Link](10);
[Link](10);
[Link](new Insets(25, 25, 25, 25));
Text scenetitle = new Text("Welcome");
[Link]([Link]("Tahoma", [Link], 20));
[Link](scenetitle, 0, 0, 2, 1);
Label userName = new Label("User Name:");
[Link](userName, 0, 1);
userTextField = new TextField();
[Link](userTextField, 1, 1);
Roll no: 2127220501126 Page no:
Label pw = new
Label("Password:"); [Link](pw, 0,
2);
PasswordField passwordBox = new PasswordField();
[Link](passwordBox, 1, 2);
passwordTextField = passwordBox;
CheckBox showPasswordCheckBox = new CheckBox("Show password");
[Link](event -> {
if ([Link]()) {
[Link]([Link]());
[Link]("");
[Link](false);
[Link](false);
passwordTextField = new
TextField([Link]());
[Link]("Password");
[Link](passwordTextField, 1, 2);
} else {
[Link]().remove(passwordTextField);
[Link]([Link]());
[Link](true);
[Link](true);
Roll no: 2127220501126 Page no:
passwordTextField = passwordBox;
Roll no: 2127220501126 Page no:
}
});
[Link](showPasswordCheckBox, 1, 3);
Button btn = new Button("Sign in");
HBox hbBtn = new HBox(10);
[Link]([Link]);
[Link]().add(btn);
[Link](hbBtn, 1, 4);
final Text actiontarget = new Text();
[Link](actiontarget, 1, 6);
[Link](e -> {
[Link]("");
String enteredUsername = [Link]();
String enteredPassword =
[Link]();
if ([Link](username) &&
[Link](password)) {
[Link]("Login Successful");
[Link]([Link]);
} else {
Roll no: 2127220501126 Page no:
[Link]("Login Unsuccessful");
[Link]([Link]);
// Do not clear the text fields after sign-in
});
Scene scene = new Scene(grid, 300, 275);
[Link](scene);
[Link]();
SAMPLE I/O:
RESULT:
Thus the Java Program to develop Student management application using
JavaFX controls has been implemented and executed successfully.
Roll no: 2127220501126 Page no:
CS22409 – JAVA PROGRAMMING: THEORY AND PRACTICES
EXP. NO:
14 DATE:
JAVAFX LAYOUTS
AIM:
To write a Java program to develop Student management application using
JavaFX layouts
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.
Roll no: 2127220501126 Page no:
PROGRAM:
import [Link];
import [Link];
import [Link].*;
import [Link].*;
import [Link];
public class exp14 extends Application {
public static void main(String[] args)
launch(args);
@Override
public void start(Stage primaryStage) {
// Create UI components
Button loginButton = new Button("Login");
Button registerButton = new Button("Register");
TextField usernameField = new TextField();
TextField passwordField = new TextField(); // Use a regular text field for
custom password input
// Layout
VBox loginLayout = new VBox(10);
Roll no: 2127220501126 Page no:
[Link]().addAll(
new Label("Username:"),
usernameField,
new Label("Password:"),
passwordField,
loginButton,
registerButton
);
Scene scene = new Scene(loginLayout, 300, 200);
[Link](scene);
[Link]("Student Management System");
[Link]();
// Event handlers
[Link](e -> handleLogin([Link](),
[Link]()));
[Link](e -> handleRegistration(usernameField,
passwordField));
private void handleLogin(String username, String password) {
// Implement login logic (check credentials)
Roll no: 2127220501126 Page no:
// For simplicity, let's assume successful login for now
[Link]("Logged in as: " + username);
private void handleRegistration(TextField usernameField, TextField passwordField)
{
// Implement registration logic (add new user to the database)
// Show success message or handle errors
// For simplicity, let's assume successful registration for now
[Link]("User registered successfully!");
// Clear text fields after registration
[Link]();
[Link]();
Roll no: 2127220501126 Page no:
SAMPLE I/O:
RESULT:
Thus the Java Program to develop Student management application using
JavaFX layouts has been implemented and executed successfully.
Roll no: 2127220501126 Page no:
Roll no: 2127220501126 Page no:
CS22409 – JAVA PROGRAMMING: THEORY AND PRACTICES
EXP. NO:
15 DATE:
JAVAFX MENUS
AIM:
To write a Java program to develop Student management application using
JavaFX menus
ALGORITHM:
1. Set up the main method and launch the JavaFX application:
a. The `main()` method is the entry point of the application.
b. It calls the `launch()` method to start the JavaFX application.
2. Implement the `start()` method to create the login screen:
c. The `start()` method is the main entry point for the JavaFX application.
d. It creates the UI components for the login screen, such as a label, text
fields, and a button.
e. It sets up the layout using a `VBox` and adds the UI components to it.
f. It creates a `Scene` object with the login layout and sets it on the
`Stage`.
g. It sets the title of the `Stage` and shows it.
3. Implement the `showDashboard()` method:
h. This method is called when the login button is clicked.
Roll no: 2127220501126 Page no:
i. It creates the UI components for the dashboard screen, such as a label
and a button.
j. It sets up the layout using a `VBox` and adds the UI components to it.
k. It creates a `Scene` object with the dashboard layout and sets it on the
`Stage`.
4. Implement the `showEnrollmentScreen()` method:
l. This method is called when the "Enroll Student" button on the
dashboard is clicked.
m. It creates the UI components for the student enrollment screen, such as a
label, a text field, and a button.
n. It sets up the layout using a `VBox` and adds the UI components to it.
o. It creates a `Scene` object with the enrollment layout and sets it on the
`Stage`.
5. Implement the event handler for the login button:
p. The `setOnAction()` method is used to attach an event handler to the
login button.
q. When the login button is clicked, the `showDashboard()` method is
called.
6. Implement the event handler for the "Enroll Student" button:
r. The `setOnAction()` method is used to attach an event handler to the
"Enroll Student" button.
s. When the "Enroll Student" button is clicked, the
`showEnrollmentScreen()` method is called.
7. Implement the event handler for the "Enroll" button on the enrollment screen:
Roll no: 2127220501126 Page no:
t. The `setOnAction()` method is used to attach an event handler to the
"Enroll" button.
u. When the "Enroll" button is clicked, the code prints a message to
the console, simulating the enrollment of a student.
PROGRAM:
import [Link];
import [Link];
import [Link].*;
import [Link];
import [Link];
public class exp15 extends Application {
private Stage primaryStage;
public static void main(String[] args) {
launch(args);
@Override
public void start(Stage primaryStage)
{ [Link] = primaryStage;
[Link]("Student Management System");
// Create login screen
Roll no: 2127220501126 Page no:
VBox loginLayout = new VBox(10);
Label loginLabel = new Label("Login");
TextField usernameField = new TextField();
PasswordField passwordField = new PasswordField();
Button loginButton = new Button("Login");
[Link](e -> showDashboard());
[Link]().addAll(loginLabel, usernameField, passwordField,
loginButton);
Scene loginScene = new Scene(loginLayout, 300, 200);
[Link](loginScene);
[Link]();
private void showDashboard() {
// Create dashboard screen
VBox dashboardLayout = new VBox(10);
Label dashboardLabel = new Label("Welcome to the Dashboard!");
Button enrollButton = new Button("Enroll Student");
[Link](e -> showEnrollmentScreen());
[Link]().addAll(dashboardLabel, enrollButton);
Scene dashboardScene = new Scene(dashboardLayout, 400, 300);
Roll no: 2127220501126 Page no:
[Link](dashboardScene);
private void showEnrollmentScreen() {
// Create student enrollment screen
VBox enrollmentLayout = new VBox(10);
Label enrollmentLabel = new Label("Student Enrollment");
TextField studentNameField = new TextField();
Button enrollStudentButton = new Button("Enroll");
[Link](e -> {
// Add logic to enroll student (e.g., save to database)
[Link]("Enrolled student: " + [Link]());
});
[Link]().addAll(enrollmentLabel, studentNameField,
enrollStudentButton);
Scene enrollmentScene = new Scene(enrollmentLayout, 400, 300);
[Link](enrollmentScene);
Roll no: 2127220501126 Page no:
SAMPLE I/O:
Roll no: 2127220501126 Page no:
RESULT:
Thus the Java Program to develop Student management application using
JavaFX menus has been implemented and executed successfully.
Roll no: 2127220501126 Page no:
Roll no: 2127220501126 Page no: