ActionListener isn't Implementing

余生颓废 提交于 2019-12-02 04:37:40

The class implements the ActionListener interface. This means that it must implement a method:

public void actionPerformed(ActionEvent)

However, the class definition you've posted does not include this method, hence why you are seeing a compilation error. To fix the code, try adding the following method:

public void actionPerformed(ActionEvent evt) {
  Object obj = packageChoice.getSelectedItem();
  JOptionPane.showMessageDialog(this, "You selected: " + obj);
}

implements ActionListener means that your class must defined the methods that are defined in the ActionListener interface. It has one method:

void actionPerformed(java.awt.event.ActionEvent);

So you must either have this method. You need it, because your button needs an action listener.

In that method you define what happens when the button is clicked.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!