I have a FormPanel class with a JButton, which has an ActionListener. I also have a subclass of EventObject calles FormPanelEvent. My question is about the ActionListeners' actionPerformed() method: If I instantiate FormPanelEvent, do I pass the FormPanel object or the JButton as the source? I have seen other people pass 'this', but isn't the JButton the actual source?
public class FormPanel extends JPanel {
private JLabel usernameLabel, passwordLabel;
private JTextField usernameField;
private JPasswordField passwordField;
private JButton submitButton, clearButton;
private Collection<FormPanelListener> formPanelListeners = new ArrayList<>();
public FormPanel() {
...
submitButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String username = usernameField.getText().trim();
char[] password = passwordField.getPassword();
FormPanelEvent e = new FormPanelEvent(this or submitButton)
}
});
...
}