Suzan Cioc
Suzan Cioc

Reputation: 30097

What to send to actionPerformed?

If I call action by myself then what should I send to actionPerformed(ActionEvent e) as e? My logic does not use this parameter so I can send null, but what is sent here regularly? If action is called by button, then what it sends here?

Upvotes: 0

Views: 61

Answers (2)

Brian
Brian

Reputation: 17299

In general, you pass 3 or 4 parts (according to the constructors for ActionEvent):

  • the source (usually a Component, but can really be anything; generally the originating piece of the UI that resulted in the event being generated),
  • the ID (almost always ActionEvent.ACTION_PERFORMED, but could also be ActionEvent.ACTION_FIRST or ActionEvent.ACTION_LAST),
  • the command string (see AbstractButton.getActionCommand),
  • and any modifiers (for example, ActionEvent.ALT_MASK | ActionEvent.SHIFT_MASK if the user held AltShift while performing the action).

The modifiers are optional, everything else is required. You can also pass a when for the timing of the event, but generally isn't necessary as it defaults to when the event was constructed.

Upvotes: 2

mprivat
mprivat

Reputation: 21902

Read the doc for ActionEvent. The constructors documentation will tell you what you want to know. For more information, you could also simply add a button and a breakpoint. Press the button and get all the details.

Upvotes: 2

Related Questions