JAVA code to make Registration,login frame for password manager project



import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JSeparator;
import javax.swing.JTextArea;
import javax.swing.JTextField;


public class MainFrame extends JPanel  {

/**
*
*/
private static final long serialVersionUID = 1L;

public MainFrame() {
     super(true);

     final JFrame frame = new JFrame("Password Encrypter & Saver");
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     JMenuBar menubar = new JMenuBar();
 JMenu loginmenu = new JMenu("Login");
 loginmenu.add(new JSeparator());
 JMenu registermenu = new JMenu("Registration");
 registermenu.add(new JSeparator());
 JMenu manualmenu = new JMenu("Help");
 manualmenu.add(new JSeparator());

          JMenuItem loginItem1 = new JMenuItem("Login to Project");
                 
 JMenuItem registerItem1 = new JMenuItem("Register to Project");

 JMenuItem manualItem1 = new JMenuItem("Manual to use Project");

 loginmenu.add(loginItem1);
 registermenu.add(registerItem1);
 manualmenu.add(manualItem1);

 menubar.add(loginmenu);
 menubar.add(registermenu);
 menubar.add(manualmenu);
 frame.setJMenuBar(menubar);
 frame.setSize(500,500);
 frame.setVisible(true);

 loginItem1.addActionListener( new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      setVisible(false);
      new Login();
     }
 });

 registerItem1.addActionListener( new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      setVisible(false);
      new Registration();
     }
 });

 manualItem1.addActionListener( new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      setVisible(false);
      new MainFrame();
     }
 });


}

public static void main(String[] args) {
new MainFrame();
/*new Login();
new Registration();
new Userframe();
new Savingframe();
new Retrievingframe();
new Showpasswordframe();*/
}
}

class Login extends JFrame
{
/**
*
*/
private static final long serialVersionUID = 1L;
final JButton loginbtn;
final JPanel lgnpanel;
final JLabel usernameLabel, passwordLabel;
final JTextField  usernameField;
final JPasswordField passwordField;

Login()
{
super("Login form");

usernameLabel = new JLabel("Username:");
usernameField = new JTextField(15);

passwordLabel = new JLabel("Password:");
passwordField = new JPasswordField(15);

loginbtn = new JButton("Login");

lgnpanel = new JPanel(new GridLayout(3,2));
lgnpanel.add(usernameLabel);
lgnpanel.add(usernameField);
lgnpanel.add(passwordLabel);
lgnpanel.add(passwordField);
lgnpanel.add(loginbtn);
// to fill the GridLayout
add(lgnpanel,BorderLayout.CENTER);
setTitle("LOGIN FRAME");
setSize(400,200);
setVisible(true);
loginbtn.addActionListener(
   new ActionListener() {
       public void actionPerformed(ActionEvent e) {
       // do something for valid login
       JOptionPane.showMessageDialog(lgnpanel,"Login successful");
       setVisible(false);
       new Userframe();
       }
   });
/*loginbtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// do something
JOptionPane.showMessageDialog(panel,"Sorry Invalid Username or Password");
new Login();
}
  });*/
}
}


class Registration extends JFrame
{
/**
*
*/
private static final long serialVersionUID = 1L;
final JButton submitBtn;
final JPanel panel;
final JLabel usernameLabel, passwordLabel,retypepasswordLabel,answerlabel;
final JTextField  usernameField,combofield,answerfield;
final JPasswordField passwordField,retypepasswordField;
final JComboBox combo;

Registration()
{
super("Registration Form");

String course[] = {"Select Security Question","your first crush?","your favourite sportperson?","Your first vehicle number?","Your lucky number?"};

usernameLabel = new JLabel("Choose Username:");
usernameField = new JTextField(15);

passwordLabel = new JLabel("Choose Password:");
passwordField = new JPasswordField(15);

retypepasswordLabel = new JLabel("Retype Password:");
retypepasswordField = new JPasswordField(15);

combo = new JComboBox(course);
combo.setBackground(Color.white);
combo.setForeground(Color.blue);

answerlabel = new JLabel("Answer of Question");
answerfield = new JTextField(20);

combofield = new JTextField(15);

submitBtn = new JButton("Submit");

panel = new JPanel(new GridLayout(6,6));
panel.add(usernameLabel);
panel.add(usernameField);
panel.add(passwordLabel);
panel.add(passwordField);
panel.add(retypepasswordLabel);
panel.add(retypepasswordField);
panel.add(combo);
panel.add(combofield);
panel.add(answerlabel);
panel.add(answerfield);
panel.add(submitBtn);
// to fill the GridLayout
panel.add(new JLabel(""));
add(panel,BorderLayout.CENTER);

setTitle("REGISTRATION FRAME");
setSize(400,300);
setVisible(true);

combo.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent ie){
String str = (String)combo.getSelectedItem();
combofield.setText(str);
 }
});

submitBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// do something for login invalid
JOptionPane.showMessageDialog(panel,"Registration Successful");
setVisible(false);
new Login();
}
  });

/*submitBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// do something
JOptionPane.showMessageDialog(panel,"Username already exists or password doesnot match");
new Registration();
}
});*/


}
}


class Userframe extends JFrame
{

/**
*
*/
private static final long serialVersionUID = 1L;

Userframe()
{
final JFrame frame = new JFrame("WELCOME username ");
 
//lgnpanel.setVisible(false);
JMenuBar menubar = new JMenuBar();
JMenu savemenu = new JMenu("Save");
JMenu retrievemenu = new JMenu("Retrieve");
JMenu logoutmenu = new JMenu("LogOut");

JMenuItem saveItem1 = new JMenuItem("Save your Passwords");
     
JMenuItem retrieveItem1 = new JMenuItem("Retrieve your Passwords");

   JMenuItem logoutItem1 = new JMenuItem("LogOut of Project");

savemenu.add(saveItem1);
retrievemenu.add(retrieveItem1);
logoutmenu.add(logoutItem1);

menubar.add(savemenu);
menubar.add(retrievemenu);
menubar.add(logoutmenu);
frame.setJMenuBar(menubar);
frame.setSize(400,300);
frame.setVisible(true);

saveItem1.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      setVisible(false);
      new Savingframe();
     }
 });

retrieveItem1.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      setVisible(false);
      new Retrievingframe();
     }
 });

logoutItem1.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      setVisible(false);
      new MainFrame();
     }
 });
}
}


class Savingframe extends JFrame
{

/**
*
*/
private static final long serialVersionUID = 1L;
final JButton saveitbtn,addmorebtn;
final JPanel panel;
final JLabel usernameLabel,websiteLabel,passwordLabel,creditfieldlabel;
final JTextField  websiteField,usernameField,creditfield;
final JPasswordField passwordField;

Savingframe()
{
super("Saving Password Frame");

websiteLabel = new JLabel("Website:");
websiteField = new JTextField(15);

usernameLabel = new JLabel("Username:");
usernameField = new JPasswordField(15);

creditfieldlabel = new JLabel("Credit Card Number");
creditfield = new JTextField(20);

passwordLabel = new JLabel("Password:");
passwordField = new JPasswordField(15);

saveitbtn = new JButton("Save It");
addmorebtn = new JButton("Add More");

panel = new JPanel(new GridLayout(6,6));
panel.add(websiteLabel);
panel.add(websiteField);
panel.add(usernameLabel);
panel.add(usernameField);
panel.add(passwordLabel);
panel.add(passwordField);
panel.add(addmorebtn);
panel.add(saveitbtn);
// to fill the GridLayout
add(panel,BorderLayout.CENTER);

setTitle("SAVING PASSWORD");
setSize(400,350);
setVisible(true);

saveitbtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// do something
JOptionPane.showMessageDialog(panel,"Saved Successfully");
setVisible(false);
new Userframe();
}
});

/*saveitbtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// do something
JOptionPane.showMessageDialog(panel,"Website or email-id already exists");
new Savingframe();
}
});*/
}
}


class Retrievingframe extends JFrame
{

/**
*
*/
private static final long serialVersionUID = 1L;
final JButton givepasswordbtn;
final JPanel panel;
final JLabel usernameLabel,websiteLabel;
final JTextField  websiteField,usernameField;

Retrievingframe()
{
super("Retreving Password Frame");

websiteLabel = new JLabel("Website:");
websiteField = new JTextField(15);

usernameLabel = new JLabel("Username:");
usernameField = new JPasswordField(15);

givepasswordbtn = new JButton("Give Password");

panel = new JPanel(new GridLayout(3,3));
panel.add(websiteLabel);
panel.add(websiteField);
panel.add(usernameLabel);
panel.add(usernameField);
panel.add(givepasswordbtn);
// to fill the GridLayout

add(panel,BorderLayout.CENTER);

setTitle("RETRIEVING PASSWORD");
setSize(400,150);
setVisible(true);

givepasswordbtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// do something
JOptionPane.showMessageDialog(panel,"Such details does not exists");
setVisible(false);
new Retrievingframe();
}
});

/*givepasswordbtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// do something
new Showpasswordframe();
}
});*/
}
}


class Showpasswordframe extends JFrame
{

/**
*
*/
private static final long serialVersionUID = 1L;
final JButton continuebtn;
final JPanel panel;
final JLabel usernameLabel,websiteLabel,passwordLabel;
final JTextField  websiteField,usernameField,passwordField;

Showpasswordframe()
{
super("Show Password Frame");

websiteLabel = new JLabel("Website:");
websiteField = new JTextField(15);

usernameLabel = new JLabel("Username:");
usernameField = new JPasswordField(15);

passwordLabel = new JLabel("Password:");
passwordField = new JPasswordField(15);

continuebtn = new JButton("Continue");

panel = new JPanel(new GridLayout(4,3));
panel.add(websiteLabel);
panel.add(websiteField);
panel.add(usernameLabel);
panel.add(usernameField);
panel.add(passwordLabel);
panel.add(passwordField);
panel.add(continuebtn);
// to fill the GridLayout
panel.add(new JLabel(""));
add(panel,BorderLayout.CENTER);

setTitle("SHOWING YOUR PASSWORD");
setSize(400,200);
setVisible(true);

continuebtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// do something
setVisible(false);
new Userframe();
}
});
}
}


Previous
Next Post »