How to create on click event for buttons in swing?

For that, you need to use ActionListener, for example:

JButton b = new JButton("push me");
b.addActionListener(new ActionListener() {

    @Override
    public void actionPerformed(ActionEvent e) {
        //your actions
    }
});

For generating click event programmatically, you can use doClick() method of JButton: b.doClick();

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)