JAVA SWING 中 AbstractButton 中的方法 addActionListener(ActionListener)对于参数不适用

JButton b1=new JButton("打印");
b1.setBounds(80,140,100,50);
b1.setBorderPainted(false);
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null,"弹出对话框");
}
});
Eclipse报错,错误为
ActionListener 无法解析为类型
- 类型 AbstractButton 中的方法 addActionListener(ActionListener)对于参数(new ActionListener()
{})不适用
这是怎么回事?感谢回答

第1个回答  2020-05-11
import java.awt.event.ActionListener;
第2个回答  2018-04-14
在你的与文件同名的类后面添加接口 implements ActionListener
第3个回答  推荐于2018-03-04
你导入错误的包了,我这样写好多次了都没问题 上面import删了ctrl + shift + o本回答被提问者和网友采纳
第4个回答  2014-12-30
代码没问题
是不是没有import相关的类

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网