Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

College of Computer Science Information & Technology

JAZAN UNIVERSITY
ACADEMIC YEAR – 2023-24, 1st Semester
Assignment 1 - 004Comp-3 - Elective - 2 [2x5=10 Marks]
Instructions -
1) Solve all of the Questions and Submit/Upload on the Blackboard.
2) You have 1 week to submit your Assignments. The Last date of submission is on 05/10/23 M.
Q.-1 Design any one JForm (without coding) with topic relevant components (Java
NetBeans) from the followings list -
 Tourism Information system
 Car Rental Information System
 Airline Information System
 Courier Information System
 Hospital management System
 Hotel Room Reservation System
 Student Information System
 Health Care System
 Sales Management System
 Airline Information System
 Banking Information System
 Receipt Generator
 Course Information System
 Library Information System
Q.-2 Describe the Model-View-Design pattern of the Dynamic Web Application.

Q.-3 Design a Login Screen with User ID & Password in Java NetBeans. Also write the
coding to enter into the login.

Certainly! Here's a design for a login screen with a User ID and Password field in Java
NetBeans, along with the code to handle the login functionality:

Design:

1. JLabel: "Login"
- This label serves as the title of the login screen.

2. JLabel: "User ID:"


- This label indicates the input field for the user ID.

3. JTextField: [User ID Input Field]


- This text field allows the user to enter their user ID.

4. JLabel: "Password:"
- This label indicates the input field for the password.
5. JPasswordField: [Password Input Field]
- This password field allows the user to enter their password.

6. JButton: "Login"
- This button triggers the login functionality.

7. JButton: "Cancel"
- This button cancels the login process.

Code:
Here's an example code snippet that demonstrates the design and login functionality for the login
screen:

```java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class LoginScreen extends JFrame {


// Components
private JLabel titleLabel;
private JLabel userIdLabel;
private JTextField userIdField;
private JLabel passwordLabel;
private JPasswordField passwordField;
private JButton loginButton;
private JButton cancelButton;

public LoginScreen() {
// Set up the frame
setTitle("Login Screen");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());

// Initialize components
titleLabel = new JLabel("Login");
userIdLabel = new JLabel("User ID:");
userIdField = new JTextField(15);
passwordLabel = new JLabel("Password:");
passwordField = new JPasswordField(15);
loginButton = new JButton("Login");
cancelButton = new JButton("Cancel");

// Add components to the frame


add(titleLabel);
add(userIdLabel);
add(userIdField);
add(passwordLabel);
add(passwordField);
add(loginButton);
add(cancelButton);

// Add action listener for the login button


loginButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String userId = userIdField.getText();
String password = new String(passwordField.getPassword());

// Perform login validation


if (userId.equals("admin") && password.equals("password")) {
JOptionPane.showMessageDialog(LoginScreen.this, "Login successful!");
// Open the main application window or perform other actions
} else {
JOptionPane.showMessageDialog(LoginScreen.this, "Invalid user ID or password.
Please try again.");
}
}
});

// Add action listener for the cancel button


cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0); // Close the application
}
});

// Set the size and make the frame visible


setSize(300, 200);
setVisible(true);
}

public static void main(String[] args) {


SwingUtilities.invokeLater(new Runnable() {
public void run() {
new LoginScreen();
}
});
}
}
```
To run this code, create a new Java project in NetBeans, create a new class file, and replace the
contents of the class file with the code above. Then, run the project to see the login screen in
action.

In the code, the login functionality is implemented inside the action listener for the login button.
The user ID and password entered by the user are retrieved from the corresponding fields. In this
example, the user ID is set to "admin" and the password is set to "password" for demonstration
purposes. You can modify these values or implement further logic to validate the user ID and
password against a database or other authentication mechanisms.

If the user ID and password match the expected values, a success message is displayed using a
JOptionPane. Otherwise, an error message is displayed.

Please note that this code only demonstrates the login screen design and basic functionality. In a
real-world application, you would need to implement appropriate security measures and handle
user authentication securely.

Q.-4 Explain the JDBC with coding.


Q.-5 Describe how the Dynamic Web Applications are better than Static Web Application.

You might also like