please help me in finding the proble in the following code
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
class button extends JButton
{
public button(String s)
{
setName(s);
setVisible(true);
}
}
class label extends JLabel
{
public label (String s)
{
setText(s);
setVisible(true);
}
}
class loginform extends JFrame implements ActionListener , TextListener
{
public Container con;
private TextField nam;
private JLabel usr,pass;
private JPasswordField pas;
private Button ok,cancel;
public loginform(String s)
{
super(s);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
Container con=getContentPane();
setResizable(false);
usr=new label("Employee Id");
pass=new label("Password");
con.add(pass);
con.add(usr);
TextField nam=new TextField();
JPasswordField pas=new JPasswordField();
con.add(nam);
con.add(pas);
nam.setEditable(true);
pas.setEditable(true);
usr.setBounds(50,50,100,25);
pass.setBounds(50,100,75,25);
nam.setBounds(150,50,150,25);
pas.setBounds(150,100,100,25);
ok=new Button("Ok");
cancel=new Button("Cancel");
con.add(ok);
con.add(cancel);
ok.setBounds(100, 150, 50, 25);
cancel.setBounds(175, 150,75, 25);
JLabel j=new JLabel("Shashank");
con.add(j);
ok.addActionListener(this);
cancel.addActionListener(this);
nam.addTextListener(this);
}
public static void main(String args[])
{
JFrame f=new loginform("Login Form");
f.setVisible(true);
f.setBounds(300,200,400,300);
f.setLayout(null);
}
public void actionPerformed (ActionEvent e)
{
Object ob=e.getSource();
if(ob==ok)
{
String u,p,us,ps;
u="shashank";
p="khede";
//us=nam.getText();
//ps=pas.getPassword();
if(u.equals(nam.getText()))
{ if(p.equals(pas.getPassword()))
{
menuform f=new menuform("Main Form");
}
}
//menuform f=new menuform("Main Form");
//setVisible(false);
}
if(ob==cancel)
{
/*try
{
nam.setText(null);
pas.setText(null);
}
catch(NullPointerException ex)
{
nam.setText("");
pas.setText("");
}*/
System.exit(0);
}
}
public void textValueChanged(TextEvent e)
{
}
}
the error is
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at loginform.actionPerformed(loginform.java:99)
at java.awt.Button.processActionEvent(Unknown Source)
at java.awt.Button.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)