ONLY RED COLOR TEXT IS PERFORMED MOVE ONE JFRAME TO ANOTHER JFRAME
package pkg.com;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Login implements ActionListener
{
JFrame jf,jf2;
JLabel l1,l2,l3,l4;
JPasswordField p2 ;
JButton b1,b2;
JTextField t1,t2;
Login()
{
jf= new JFrame("Login form");
jf.setBackground(Color.BLUE);
jf.setSize(250,300);
jf.setVisible(true);
jf.setResizable(false);
jf.setLayout(new FlowLayout(FlowLayout.CENTER));
l1 = new JLabel("UserName ");
t1 = new JTextField(20);
l2 = new JLabel("Password");
p2 = new JPasswordField(20);
b1= new JButton("submit");
b2= new JButton("Reset");
l3 = new JLabel();
l4 = new JLabel();
jf.add(l1);
jf.add(t1);
jf.add(l2);
jf.add(p2);
jf.add(b1);
jf.add(b2);
jf.add(l3);
jf.add(l4);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
String s1=t1.getText();
String s2 = p2.getText();
if((s1.equalsIgnoreCase("adim"))&&(s2.equals("admin")))
{
jf2=new JFrame();
jf2= new JFrame("Login form");
jf2.setBackground(Color.BLUE);
jf2.setSize(550,600);
jf2.setVisible(true);
jf.setVisible(false);
jf.dispose();
jf2.setResizable(false);
jf2.setLayout(new FlowLayout(FlowLayout.CENTER));
l1= new JLabel("welcome mr admin");
Font p1 = new Font("times new roman", Font.BOLD,30);
l1.setFont(p1);
jf2.add(l1);
}else
{
l3.setText("worng username");
l4.setText("wrong password");
}
}
if(e.getSource()==b2)
{
t1.setText(null);
p2.setText(null);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Login l = new Login();
}
}
No comments:
Post a Comment