11. Design an user interface to check the validity of username and password entered by comparing it
with the data in the back end.
11. Design an user interface to check the validity of username and password entered by comparing it
with the data in the back end.
//
//O database used:
// Java Program to enter name and password
// using JTextField and JPasswordField
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
class Program11 extends JFrame implements ActionListener {
// JTextField
static JTextField t,t1,t2;
// JPasswordField
static JPasswordField pass;
// JFrame
static JFrame f;
// JButton
static JButton b;
// label to display text
static JLabel l,l1,l2;
// default constructor
static JTextArea area;
// main class
public static void main(String[] args)
{
f = new JFrame("textfield");
l = new JLabel("nothing entered");
//l.setBounds(250, 200, 250, 250);
area = new JTextArea();
area.setBounds(250, 200, 250, 100);
b = new JButton("submit");
Program11 te = new Program11();
b.addActionListener(te);
l1 = new JLabel("user name");
l1.setBounds(50, 50, 250, 30);
t = new JTextField("enter name", 16);
t.setBounds(250, 50, 250, 30);
b.setBounds(280, 380, 100, 40);
l2 = new JLabel("password ");
l2.setBounds(50, 150, 250, 30);
// create a object of passwordField with 16 columns
pass = new JPasswordField(16);
pass.setBounds(250, 150, 250, 30);
// create an object of font type
Font fo = new Font("Serif", Font.ITALIC, 20);
t.setFont(fo);
f.add(l1);
f.add(l2);
f.add(t);
f.add(pass);
f.add(b);
f.add(area);
f.setSize(500, 500);
f.setLayout(null);
f.show();
}
public void actionPerformed(ActionEvent e)
{
String s = e.getActionCommand();
if (s.equals("submit")) {
// set the text of the label to the text of the field
String user="admin",password="admin123";
area.setText("name = " + t.getText() + "\t Password = " + pass.getText());
if(user.equals(t.getText()) && password.equals(pass.getText()))
{
area.setText(" Welcome : Login is successful\n " +"name = " + t.getText() + "\n Password = " + pass.getText());
}
else
{
area.setText("name = " + t.getText() + "\t Password = " + pass.getText() +"\n enter admin :admin123");
}
// set the text of field to blank
t.setText(" ");
// set the text of password field to blank
pass.setText("");
}
}
}