0

Because there is of no use manually edit the automatically Generated Code, how can I creat an Action object and attach this action to one or more components on a form?

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
camiluslim
  • 35
  • 1
  • 4

1 Answers1

1
  • Right-click on the component, like a button
  • in the pop-up menu select Events -> [Type of Event] -> method. Eg. Events -> Action -> actionPerformed
  • Then you will see auto-generated code like

    private void jButton1ActionPerformed(java.awt.events.ActionEvent evt) {
        // write your code here
    }
    
  • Netbeans will auto-generate the adding of a listener to the component, in the uneditable initComonents() that you can see.

If you have a custom Action class, you can always, in your GUI class constructor, add the Action object to the component right after the initComponents()

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720