Unknown error

0 Shaheedul Islam · August 6, 2015
Line 38: The type Tuna.TheHandler must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)
Line 40: The method actionPeformed(ActionEvent) from the type Tuna.TheHandler is never used locally

Can you explain to me why I get these errors. When I run the program, if I press enter the program gives me quite a lot of errors. HERE IS THE CODE:


import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JOptionPane;
public class Tuna extends JFrame{ //Inherits everything from JFrame
private JTextField item1;
private JTextField item2;
private JTextField item3;
private JPasswordField item4;
public Tuna()
{
super("The title");
setLayout(new FlowLayout());

item1 = new JTextField(10);
add(item1);

item2 = new JTextField("Enter Text here: ");
add(item2);

item3 = new JTextField("Uneditable", 3);
item3.setEditable(false);
add(item3);

item4 = new JPasswordField("My password: ");
add(item4);

TheHandler handler = new TheHandler(); 
item1.addActionListener(handler);
item2.addActionListener(handler);
item3.addActionListener(handler);
item4.addActionListener(handler);
}

private class TheHandler implements ActionListener //ERROR LINE 38
{
public void actionPeformed(ActionEvent event) //ERROR LINE 40
{
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() == item2)
{
string = String.format("field 2: %s", event.getActionCommand());
}
else if (event.getSource() == item4)
{
string = String.format("field 4: %s", event.getActionCommand());
}

JOptionPane.showMessageDialog(null, string);
}


}
}


Post a Reply

Replies

Oldest  Newest  Rating
0 Shaheedul Islam · August 6, 2015
Sorry, it's because I spelt  actionPerformed wrong
  • 1

Java / Android Development

107,147 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator