CS202 Spring2025
Java GUI Lab
Objective
The goal of this exercise is to create a Java Swing application with two GUI screens.
Your application should have two main windows (JFrame):
• Screen 1: Login Screen
• Screen 2: Welcome Screen
Screen 1: Login Screen:
Create a JFrame with the title "Login Screen".
The window should contain the following components:
• A JLabel with the text "Username:".
• A JTextField for the user to enter their username.
• A JLabel with the text "Password:".
• A JPasswordField for the user to enter their password.
• A JButton labeled "Login".
• A JButton labeled "Exit".
Screen 2: Welcome Screen:
Create another JFrame with the title "Welcome Screen".
The window should contain the following components:
• A JLabel that displays a welcome message, e.g., "Welcome, [Username]!".
• A JButton labeled "Logout" to return to the Login Screen.
Functionality:
Login Screen:
CS202 Spring2025
• When the "Login" button is clicked, check if the username and password are both
non-empty.
• If valid, hide the Login Screen and display the Welcome Screen with a greeting
message.
• If either field is empty, display an error message using a JOptionPane.
• The "Exit" button should close the application.
Welcome Screen:
• The "Logout" button should hide the Welcome Screen and redisplay the Login
Screen.