Again same problem?
This program executes JTextField and JPasswordField.But the problem is I use Eclipse Platform and It shows error in line 43.The error is:
class must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)
But I've already implement that.And that's why I can't understand what's the actual problem.I've already faced the problem beforr but couldn't solve the problem although I got the help of the forum.Plz help me now.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
publicclass TextFieldTestextends JFrame{
private JTextField textfield1,textfield2,textfield3;
private JPasswordField passwordfield;
public TextFieldTest()
{
super("Testing JTextField and JPasswordField");
Container container=getContentPane();
container.setLayout(new FlowLayout());
textfield1=new JTextField(10);
container.add(textfield1);
textfield2=new JTextField("Enter text here");
container.add(textfield2);
textfield3=new JTextField("Uneditable text field",20);
textfield3.setEditable(false);
container.add(textfield3);
passwordfield=new JPasswordField("123456");
container.add(passwordfield);
TextFieldHandler handler=new TextFieldHandler();
textfield1.addActionListener(handler);
textfield2.addActionListener(handler);
textfield3.addActionListener(handler);
passwordfield.addActionListener(handler);
setSize(325,100);
setVisible(true);
}
publicstaticvoid main(String[] args){
TextFieldTest test=new TextFieldTest();
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
privateclass TextFieldHandlerimplements ActionListener
{
publicvoid actionPerformed(ActionEvent event)
{
String str="";
if(event.getSource()==textfield1)
{
str="textfield1: "+event.getActionCommand();
}
elseif(event.getSource()==textfield2)
{
str="textfield2: "+event.getActionCommand();
}
elseif(event.getSource()==textfield3)
{
str="textfield3: "+event.getActionCommand();
}
elseif(event.getSource()==passwordfield)
{
str="passwordfield: "+new String(passwordfield.getPassword());
}
JOptionPane.showMessageDialog(null,str);
}
}
}

