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

Java Login Form with JTextField

Ajp practical 12

Uploaded by

Akash Khurd
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)
6 views3 pages

Java Login Form with JTextField

Ajp practical 12

Uploaded by

Akash Khurd
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

//program to demonstrate the use of JTextField JPasswordField using Listener Interface.

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

public class LoginForm extends JFrame implements ActionListener {


private Container container;
private JLabel userLabel, passwordLabel;
private JTextField userTextField;
private JPasswordField passwordField;
private JButton loginButton;

public LoginForm() {
setTitle("Login Form");
setSize(400, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
container = getContentPane();
[Link](null);

userLabel = new JLabel("Username:");


[Link](50, 30, 100, 30);
[Link](userLabel);

userTextField = new JTextField();


[Link](150, 30, 150, 30);
[Link](userTextField);

passwordLabel = new JLabel("Password:");


[Link](50, 70, 100, 30);
[Link](passwordLabel);
passwordField = new JPasswordField();
[Link](150, 70, 150, 30);
[Link](passwordField);

loginButton = new JButton("Login");


[Link](150, 110, 150, 30);
[Link](loginButton);

[Link](this);
}

public void actionPerformed(ActionEvent e) {


String username = [Link]();
String password = new String([Link]());
[Link]("Username: " + username);
[Link]("Password: " + password);
}

public static void main(String[] args) {


LoginForm form = new LoginForm();
[Link](true);
}
}
//Program Code

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

public class PasswordFieldExample extends JFrame {


private JPasswordField passwordField;

public PasswordFieldExample() {
setTitle("Password Field Example");
setSize(400,250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());

passwordField = new JPasswordField(25);


[Link]('#');

add(passwordField);

setVisible(true);
}

public static void main(String[] args) {


new PasswordFieldExample();
}
}

You might also like