/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author elcot
*/



import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JOptionPane;


public class Eventhandling extends JFrame{

private JTextField item1;
private JTextField item2;
private JTextField item3;
private JPasswordField password;

Eventhandling(){
super("Login Form");
setLayout(new FlowLayout());
setSize(150,250);
setVisible(true);

item1=new JTextField(10);
item2=new JTextField(10);
item3=new JTextField(10);
password=new JPasswordField(10);
add(item1);
add(item2);
add(item3);
add(password);
item3.setEditable(false);

// implementing action listener



thehandler handler=new thehandler();
item1.addActionListener(handler);
item2.addActionListener(handler);
item3.addActionListener(handler);
password=addActionListener(handler);
}

// creating action handler

private class thehandler implements ActionListener
{
public void actionperformed(ActionEvent event){

String string="";
if(event.getSource()==item1)
string=String.format("field 1 %s", event.getActionCommand());
else if (event.getSource()==item2)
string=String.format("Field 2 %s", event.getActionCommand());
else if (event.getSource()==item3)
string = String.format("field 3 %s", event.getActionCommand());
else if(event.getSource()==password)
string=String.format("password is %s", event.getActionCommand());

JOptionPane.showMessageDialog(rootPane, string);


}
}





public static void main(String args[]){


Eventhandling n=new Eventhandling();
}

}