UI_Designer tutorial

I worked through the Intelij tutorial for building a simple form with code.

My question is why does the example program have an actionlistener added to the okay button inside the class definition and then another actionlistener added to the cancel button, but this time it's inside main(), ie:

public class Subscriber {

private JButton okayButton;

public Subscriber() {

okayButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {

}
});
}

public static void main(String[] args){
Subscriber form = new Subscriber();

form.cancelButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
frame.dispose();
}
});
}

}

Why not have the cancel button actionlistener inside the class definition???



Please sign in to leave a comment.