0% found this document useful (0 votes)
8 views1 page

Java Swing Login Form Example

This Java program creates a simple login form using Swing. It includes fields for username and password, and a login button that validates the credentials against predefined values. If the login is successful, a message is displayed; otherwise, an error message appears.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Java Swing Login Form Example

This Java program creates a simple login form using Swing. It includes fields for username and password, and a login button that validates the credentials against predefined values. If the login is successful, a message is displayed; otherwise, an error message appears.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import [Link].

*;
import [Link].*;
import [Link].*;

public class LoginForm implements ActionListener {

JFrame frame;
JLabel userLabel, passLabel;
JTextField userText;
JPasswordField passText;
JButton loginBtn;

LoginForm() {
frame = new JFrame("Login Form");
[Link](350, 250);
[Link](null);
[Link](JFrame.EXIT_ON_CLOSE);

userLabel = new JLabel("Username:");


[Link](40, 40, 80, 25);

userText = new JTextField();


[Link](130, 40, 150, 25);

passLabel = new JLabel("Password:");


[Link](40, 80, 80, 25);

passText = new JPasswordField();


[Link](130, 80, 150, 25);

loginBtn = new JButton("Login");


[Link](130, 130, 80, 30);
[Link](this);

[Link](userLabel);
[Link](userText);
[Link](passLabel);
[Link](passText);
[Link](loginBtn);

[Link](true);
}

public static void main(String[] args) {


new LoginForm();
}

@Override
public void actionPerformed(ActionEvent e) {
String user = [Link]();
String pass = new String([Link]());

if ([Link]("admin") && [Link]("1234")) {


[Link](frame, "Login Successful ✅");
} else {
[Link](frame, "Invalid Username or Password ❌");
}
}
}

You might also like