I wrote this program to tinker with event listeners and such.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Test extends JFrame {
public Test() {
super("Test");
setSize(300, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextField searchBar = new JTextField(20);
searchBar.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
// do something
}
});
JButton search = new JButton("Search");
FlowLayout flo = new FlowLayout();
setLayout(flo);
add(searchBar);
add(search);
setVisible(true);
}
public static void main(String[] args) {
Test test = new Test();
}
}
If I leave the program like that it’s fine. But if I try to do “implements ActionListener” at the top, it gives me a warning. I’m using Eclipse, and it says, “The type Test must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)” Why is it doing this? It won’t even let me do “searchBar.addActionListener(this)” and then “public void actionPerformed(ActionEvent evt) {}” How come? Thanks for the help.