0% found this document useful (0 votes)
11 views

Tutorial 13

Uploaded by

pilot250504
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Tutorial 13

Uploaded by

pilot250504
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Programming 2

Tutorial 13
Exercise 1 (required)
Design the interface of the login feature as shown in the following image:

GUIDELINES:

Import necessary libraries:

Declare classes and components

o The LoginGui class is declared, which implements the ActionListener


interface to handle button click events.
Create main method:

The main method is the entry point of the application. Inside this method:
o A JFrame window named frame and titled "Login Form" is created.
o A JPanel named panel is created to hold the components.
o The size and default close operation are set for the window, and panel is added
to the window’s CENTER position (because JFrame uses BorderLayout by
default).
Create and configure title label

o A JLabel named lblTitle is created to display the title "Simple Login Form".
The label is set to:

 Takes the entire width of the container (so that no component will be
placed on the same line as itself).

 Have center text alignment.

 Use a bold Arial font with a size of 20.

Create and configure user components

o Components for entering the username are created:

 lblUser: A label displaying "User".

 txtUser: A text field for entering the username.

Create and configure password components

o Components for entering the password are created:

 lblPass: A label displaying "Password".

 txtPass: A password field for entering the password.


Create and configure Login button

o A JButton named btnLogin is created with the text "Login". An action listener
is added to the button to handle button click events.

Create and configure Success/Failure label

o A JLabel named lblSuccess is created to display the login status message.

Implement ActionListener

o The actionPerformed method is implemented to handle the button click event.


It retrieves the entered username and password, checks if they match the
expected values, and updates the success label accordingly.
Run the Application

o Finally, the main method ends by resizing the frame to fit the Jpanel container
and making the frame visible, allowing user to interact with the Login Form.

You might also like