ActionListener不会触发事件

时间:2013-10-19 21:28:38

标签: java swing actionlistener

当我运行这个时,我得到调试消息“Listener has made”,因此他们已经成为了一个内部类AddSpectrumGraphListener对象。 但是actionlistener不会响应按钮的点击。

有人看到我犯的错误吗?

我的控制器类:

public class Controller {

    private Model model;
    private MainFrame mainFrame;

    public Controller(Model model, MainFrame view){
        this.model = model;
        this.mainFrame = view;

        mainFrame.getLeftBar().getSpecPanel()
                .addCreateSpectrumGraphButtonListener(new AddSpectrumGraphListener());    
    }

    public class AddSpectrumGraphListener implements ActionListener {

        public AddSpectrumGraphListener(){
            super();
            System.out.println("Listener has been made");
        }

        @Override
        public void actionPerformed(ActionEvent e) {

            System.out.println(" triggerd");      

        }
    }
}

带有按钮的JPanel类:

public class SpectrumEditPanel extends JPanel{

    private JButton createGraphBttn;

    public SpectrumEditPanel (){
        super(new GridLayout(0,1));

        // Button
        createGraphBttn = new JButton("Maak Grafiekie");
        add(createGraphBttn);

    }

    public void addCreateSpectrumGraphButtonListener(ActionListener al) {
        createGraphBttn.addActionListener(al);
    } 
}

我在这里添加了完整的代码: https://www.dropbox.com/s/y03dal7qn4rwqqo/TFVsimulation.zip

提前谢谢你!

0 个答案:

没有答案