【发布时间】:2018-08-11 22:14:29
【问题描述】:
我收到一个未解决的编译错误。出现这些错误:
类型中的方法addActionListener(ActionListener) AbstractButton 不适用于参数(Gui.HandlerClass) 类型中的方法addActionListener(ActionListener) AbstractButton 不适用于参数(Gui.HandlerClass) ActionListener 无法解析为 ActionEvent 类型无法解析 解析为一个类型
import java.awt.*;
import javax.swing.*;
public class Gui extends JFrame{
private JButton reg;
private JButton custom;
public Gui(){
super("The title");
setLayout(new FlowLayout());
reg = new JButton("Regular Button");
add(reg);
Icon b = new ImageIcon(getClass().getResource("foto 1.png"));
Icon c = new ImageIcon(getClass().getResource("foto 2.png"));
custom = new JButton("Custom", b);
custom.setRolloverIcon(c);
add(custom);
HandlerClass handler = new HandlerClass();
reg.addActionListener(handler);
custom.addActionListener(handler);
}
private class HandlerClass implements ActionListener{
public void actionPerformed(ActionEvent event) {
JOptionPane.showMessageDialog(null, String.format("%s", event.getActionCommand()));
}
}
}
【问题讨论】:
标签: actionlistener eventhandler actionevent