source code: login.java


import java.awt.*;
import java.awt.event.*;
class login extends Frame implements ActionListener
{
TextField t1,t2;
public login()
{
FlowLayout fl=new FlowLayout();
setLayout(fl);
Label l1=new Label("user name");
Label l2=new Label("password");
 t1=new TextField(15);
 t2=new TextField(15);
Button b1=new Button("ok");
Button b2=new Button("cancel");
add(l1);add(t1);
add(l2);add(t2);
add(b1);add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String s=ae.getActionCommand();
System.out.println("bt pressed is "+s);
if(s.equals("ok"))
{
String name=t1.getText();
String pass=t2.getText();
System.out.println("user name "+name+" password "+pass);
}
if(s.equals("cancel"))
{
t1.setText(" ");
t2.setText(" ");
}
}
public static void main(String as[])
{
login f=new login();
f.setSize(300,300);
f.setVisible(true);
}
}


output:

I:\sysem3>javac login.java

I:\sysem3>java login
bt pressed is ok
user name dbj college password csdept