0

当我尝试运行此代码时,我收到此错误:

Multiple markers at this line
    - Line breakpoint:CastleDefenders [line: 45] - CastleDefenders()
    - The method addActionListener(ActionListener) in the type AbstractButton is not applicable 
     for the arguments (CastleDefenders)

代码:

public CastleDefenders(){
    button = new JButton("Go!");
    lvl1.setToolTipText("Play the game on Easy");
    lvl2.setToolTipText("Play the game on Normal");
    lvl3.setToolTipText("Play the game on Hard");
    lvl1.setActionCommand("Easy");
    lvl2.setActionCommand("Normal");
    lvl3.setActionCommand("Hard");
    lvls.add(lvl1);
    lvls.add(lvl2);
    lvls.add(lvl3);
    pnl2.add(lvl1);
    pnl2.add(lvl2);
    pnl2.add(lvl3);
    button.addActionListener(this);
    tlkt = Toolkit.getDefaultToolkit();
    timer = new Timer();
    pnl2.setBounds(50, 5, 1, 10);
    btn.setBounds(220, 240, 5, 1);
    f.setJMenuBar(mb2);
    g.setJMenuBar(mb2);
    mnuFile.add(mnuItemQuit);
    mnuHelp.add(mnuItemAbout);
    mb.add(mnuFile);
    mb.add(mnuHelp);
    mb2.add(mnuFile);
    mb2.add(mnuHelp);
    pnl.add(btn);
    pnl2.add(lbl);
    pnl2.add(button);
    lbl.setBounds(0, 240, 10, 2);
    lbl.setEditable(false);
    f.getContentPane().setLayout(new BorderLayout());
    f.getContentPane().add(pnl, BorderLayout.CENTER);       
    f.addWindowListener(new ListenCloseWdw());
    g.getContentPane().setLayout(new BorderLayout());
    g.getContentPane().add(pnl2);   
    g.addWindowListener(new ListenCloseWdw());
    mnuItemAbout.addActionListener(new GetAboutInfo());     
    btn.addActionListener(new GetButtonClick());    
    mnuItemQuit.addActionListener(new ListenMenuQuit());
    add(button);


}
4

2 回答 2

0

如果你想让你的类监听动作事件,你需要你的CastleDefenders类来实现接口。ActionListener从错误消息看来,您还没有这样做。

于 2013-04-12T22:12:33.313 回答
0

在该行中: button.addActionListener(this); CastleDefenders 的类型是什么?CastleDefenders 是否实现了 ActionListener?

于 2013-04-12T22:14:12.840 回答