如何在GUI jButton中添加监听器?

时间:2013-02-26 22:43:22

标签: java swing actionlistener onclicklistener

    JButton bkButton = new JButton(new ImageIcon("src/Images/smallBArrow.bmp"));
    JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(bkButton);

使用动作监听器我需要能够单击并执行操作(返回,转发或刷新)

1 个答案:

答案 0 :(得分:5)

通常使用匿名内部类...

bkButton.addActionListener(new ActionListener() { 
    public void actionPerformed(ActionEvent e) { 
        backButtonPressed();
    } 
});

请参阅this回答