Issue
So i read this to learn about Event sources, event objects and event handlers and their implementation which looks like this:
aButton.addActionListener(new ActionAdapter()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
But i noticed when Netbeans creates an ActionPerformed handler(?) it looks like this:
private void aButtonActionPerformed(java.awt.event.ActionEvent evt) {
}
Do they have the same functionality or am i missing something?, and if they do, how do the netbeans way works?
Solution
If you look more carefully at the NetBeans-generated code, you will see that inside initComponents()
there is this code:
aButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
aButtonActionPerformed(evt);
}
});
that is exactly the standard implementation that you pointed out in your question.
NetBeans use this structure to prevent edits on the standard code that could lead to incorrect event handling, allowing you at the same time to write the code you need to be executed when that event happens.
Answered By - Luca Negrini