Java: actionPerformed method not firing when button clicked

前端 未结 3 1267
名媛妹妹
名媛妹妹 2021-01-19 09:51

I\'m creating a gui application that requires some simple input, however, when I click the button in the JFrame the actionPerformed method I\'m using is not fired/firing (no

相关标签:
3条回答
  • 2021-01-19 10:24

    You must add an "addActionListener to your button

    0 讨论(0)
  • 2021-01-19 10:27

    You need to add an action listener to your button component like this.

    closeButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            closeButtonActionPerformed(evt);
        }
    });
    
    private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {
        dispose();
    }
    
    0 讨论(0)
  • 2021-01-19 10:31

    You could also use @182Much's method as was discussed here: java detect clicked buttons Hope it is helpful if there are still concerns.

    0 讨论(0)
提交回复
热议问题