0% found this document useful (0 votes)
38 views22 pages

Sandhya Java

The document describes a Java program to develop a student management application using JavaFX controls and layouts. It outlines the steps to create the user interface, set up event handlers, and implement login and registration functionality using JavaFX components like buttons, text fields, labels and layouts like VBox and GridPane.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views22 pages

Sandhya Java

The document describes a Java program to develop a student management application using JavaFX controls and layouts. It outlines the steps to create the user interface, set up event handlers, and implement login and registration functionality using JavaFX components like buttons, text fields, labels and layouts like VBox and GridPane.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

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 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;

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) {

primaryStage.setTitle("JavaFX Login

Example");

GridPane grid = new GridPane();

grid.setAlignment(Pos.CENTER);

grid.setHgap(10);

grid.setVgap(10);

grid.setPadding(new Insets(25, 25, 25, 25));

Text scenetitle = new Text("Welcome");

scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));

grid.add(scenetitle, 0, 0, 2, 1);

Label userName = new Label("User Name:");

grid.add(userName, 0, 1);

userTextField = new TextField();

grid.add(userTextField, 1, 1);
Roll no: 2127220501126 Page no:
Label pw = new

Label("Password:"); grid.add(pw, 0,

2);

PasswordField passwordBox = new PasswordField();

grid.add(passwordBox, 1, 2);

passwordTextField = passwordBox;

CheckBox showPasswordCheckBox = new CheckBox("Show password");

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;

Roll no: 2127220501126 Page no:


}

});

grid.add(showPasswordCheckBox, 1, 3);

Button btn = new Button("Sign in");

HBox hbBtn = new HBox(10);

hbBtn.setAlignment(Pos.CENTER);

hbBtn.getChildren().add(btn);

grid.add(hbBtn, 1, 4);

final Text actiontarget = new Text();

grid.add(actiontarget, 1, 6);

btn.setOnAction(e -> {

actiontarget.setText("");

String enteredUsername = userTextField.getText();

String enteredPassword =

passwordTextField.getText();

if (enteredUsername.equals(username) &&
enteredPassword.equals(password)) {

actiontarget.setText("Login Successful");

actiontarget.setFill(Color.GREEN);

} else {

Roll no: 2127220501126 Page no:


actiontarget.setText("Login Unsuccessful");

actiontarget.setFill(Color.RED);

// Do not clear the text fields after sign-in

});

Scene scene = new Scene(grid, 300, 275);

primaryStage.setScene(scene);

primaryStage.show();

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 javafx.application.Application;

import javafx.scene.Scene;

import javafx.scene.control.*;

import javafx.scene.layout.*;

import javafx.stage.Stage;

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:


loginLayout.getChildren().addAll(

new Label("Username:"),

usernameField,

new Label("Password:"),

passwordField,

loginButton,

registerButton

);

Scene scene = new Scene(loginLayout, 300, 200);

primaryStage.setScene(scene);

primaryStage.setTitle("Student Management System");

primaryStage.show();

// Event handlers

loginButton.setOnAction(e -> handleLogin(usernameField.getText(),


passwordField.getText()));

registerButton.setOnAction(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

System.out.println("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

System.out.println("User registered successfully!");

// Clear text fields after registration

usernameField.clear();

passwordField.clear();

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 javafx.application.Application;

import javafx.scene.Scene;

import javafx.scene.control.*;

import javafx.scene.layout.VBox;

import javafx.stage.Stage;

public class exp15 extends Application {

private Stage primaryStage;

public static void main(String[] args) {

launch(args);

@Override

public void start(Stage primaryStage)

{ this.primaryStage = primaryStage;

primaryStage.setTitle("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");

loginButton.setOnAction(e -> showDashboard());

loginLayout.getChildren().addAll(loginLabel, usernameField, passwordField,


loginButton);

Scene loginScene = new Scene(loginLayout, 300, 200);

primaryStage.setScene(loginScene);

primaryStage.show();

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");

enrollButton.setOnAction(e -> showEnrollmentScreen());

dashboardLayout.getChildren().addAll(dashboardLabel, enrollButton);

Scene dashboardScene = new Scene(dashboardLayout, 400, 300);

Roll no: 2127220501126 Page no:


primaryStage.setScene(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");

enrollStudentButton.setOnAction(e -> {

// Add logic to enroll student (e.g., save to database)

System.out.println("Enrolled student: " + studentNameField.getText());

});

enrollmentLayout.getChildren().addAll(enrollmentLabel, studentNameField,
enrollStudentButton);

Scene enrollmentScene = new Scene(enrollmentLayout, 400, 300);

primaryStage.setScene(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:

You might also like