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

Simple Java Swing Login Form Code

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

Simple Java Swing Login Form Code

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

Practical 12

import [Link].*;

import [Link].*;

import [Link];

import [Link];

public class SimpleLoginForm extends JFrame{

public SimpleLoginForm() {

// Create the frame

setTitle("Simple Login Form");

setSize(300, 150);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setLocationRelativeTo(null);

// Create components

JLabel usernameLabel = new JLabel("Username:");

JTextField usernameField = new JTextField(15);

JLabel passwordLabel = new JLabel("Password:");

JPasswordField passwordField = new JPasswordField(15);

JButton loginButton = new JButton("Login");

// Set up the layout

setLayout(new GridLayout(3, 2));


// Add components to the frame

add(usernameLabel);

add(usernameField);

add(passwordLabel);

add(passwordField);

add(loginButton);

// Add ActionListener to the button

[Link](new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

String username = [Link]();

String password = new String([Link]());

[Link](null, "Username: " + username + "\nPassword: " +


password);

});

public static void main(String[] args) {

SimpleLoginForm form = new SimpleLoginForm();

[Link](true);

}
}

Output:

You might also like