0

当我运行它时,我收到调试消息“Listener has been 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

先感谢您!

4

0 回答 0