actionPerformed Question.
I want to get a better understand of the following code:
Code :
exitItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});
I know that the method addActionListener has to have the parameters of an ActionListener which defines what to do when the action occurs.
The part which I dont understand is the parameter of the actionPerformed method, I can see that it accepts an ActionEvent object and is calling it "e", my question is what does it do with the object?
Re: actionPerformed Question.
It does whatever you want it to do. From that parameter, you can get things like the time the event occurred, which keys were pressed at the time, etc. Different Events will have different properties- a MouseEvent has x, y, which button was clicked, etc.
Your first stop for questions like these should always be the API: ActionEvent (Java Platform SE 6)