0% found this document useful (0 votes)
58 views3 pages

Java Swing Login Form Example

This document contains a Java code example to create a login form using Swing components. The code defines labels, text fields, buttons and panels to build the form layout. It also includes validation logic that checks the username and password on submit and displays the appropriate message. Screenshots show the blank login form, an incorrect credentials message, and a successful login message. The purpose is to demonstrate creating a login interface in Java using Swing.

Uploaded by

Lucky Lucky
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views3 pages

Java Swing Login Form Example

This document contains a Java code example to create a login form using Swing components. The code defines labels, text fields, buttons and panels to build the form layout. It also includes validation logic that checks the username and password on submit and displays the appropriate message. Screenshots show the blank login form, an incorrect credentials message, and a successful login message. The purpose is to demonstrate creating a login interface in Java using Swing.

Uploaded by

Lucky Lucky
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DES’s NMITD JAVA ASSINGMENT MCA-1945

Q.1) Create a feedback form or Login page using Swings or AWT components.

import [Link].*;

import [Link].*;

import [Link].*;

@SuppressWarnings("serial")

public class Logindem extends JFrame implements ActionListener {

JPanel panel;

JLabel user_label, password_label, message;

JTextField userName_text;

JPasswordField password_text;

JButton submit, cancel;

Logindem() {

user_label = new JLabel();

user_label.setFont(new [Link]("Arial", 1, 14));

user_label.setText("User Name :");

userName_text = new JTextField();

userName_text.setSize(10, 5);

password_label = new JLabel();

password_label.setFont(new [Link]("Arial", 1, 14));

password_label.setText("Password :");

password_text = new JPasswordField();

submit = new JButton("SUBMIT");

panel = new JPanel(new GridLayout(3, 1));

[Link](user_label);

[Link](userName_text);
DES’s NMITD JAVA ASSINGMENT MCA-1945
[Link](password_label);

[Link](password_text);

message = new JLabel();

[Link](message);

[Link](submit);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// Adding the listeners to components..

[Link](this);

add(panel, [Link]);

setTitle(" Login ");

setSize(450,200);

setVisible(true);

public static void main(String[] args) {

new Logindem();

@Override

public void actionPerformed(ActionEvent ae) {

String userName = userName_text.getText();

String password = password_text.getText();

if ([Link]().equals("admin") && [Link]().equals("admin")) {

[Link](" Hello " + userName + "");

} else {

[Link](" Invalid user.. ");

}
DES’s NMITD JAVA ASSINGMENT MCA-1945

SCREENSHOTS :-

Login Frame.

Incorrect credentials.

Success Login.

You might also like