Java: actionPerformed method not firing when button clicked

前端 未结 3 1292
名媛妹妹
名媛妹妹 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: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();
    }
    

提交回复
热议问题