读书人

初学者做个黑桃王有关问题不断

发布时间: 2013-02-25 10:23:36 作者: rapoo

菜鸟做个黑桃王,问题不断啊求助
用的是Eclipse Juno JRE是1.7
CardJFrame extends JFrame 是主程序类
public class userop implements ActionListener{

public userop(JPanel useropPanel,CardJFrame supframe,int usern)
{
JButton bidpp=new JButton("+");
bidpp.setBounds(150,10,45,30);
useropPanel.add(bidpp);
bidpp.addActionListener(supframe);//这里报错
.....
}
public void actionPerformed(ActionEvent evt) {
// TODO Auto-generated method stub

Object src = evt.getSource();
if (src == bidpp) {

}


}

是这样写的吧?
我看到有人是
bidpp.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {


我不喜欢在一个参数里写一个函数,这个太头重脚轻了
[解决办法]

引用:
上面的问题是The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments CardJFrame

在你的程序里面userop实现了ActionListener,而不是CardJFrame,所以应该改为bidpp.addActionListener(this);
[解决办法]
引用:
引用:
谢谢,我不想把所有的ActionListener都写在一起
想出来一个办法 public class userop extends CardJFrame
那样就把设分、打牌等工作用不同的ActionListener了
要用到主框架的东西用super.就可以了

我觉得这不是个好的办法,最好实现不同的ActionListener来分离这些不同的需求

读书人网 >J2SE开发

热点推荐