Action Listener Flashcards
1
Q
Action Listener
A
Event handlers, what should be done when a user performs certain operations
2
Q
Action Event Examples
A
User clicks a button
Chooses a menu item
Presses Enter in a text field
3
Q
Write Action Listener Steps
A
Declare event handler class either implements ActionListener interface or extends class that implements ActionListener interface Register instance of event handler class as a listener on component Include code that reacts to the action
4
Q
Write Action Listener Code
A
public class MyClass implements ActionListener { someComponent.addActionListener(instanceOfMyClass); public void actionPerformed(ActionEvent e) { //reaction code } }
5
Q
addActionListener method
A
Program registers object as action listener on button or event source
6
Q
ActionEvent argument
A
Single argument gives information about event and its source
7
Q
Action Listener Interface
actionPerformed(actionEvent)
A
Called just after the user performs an action
8
Q
Action Event Class String getActionCommand()
A
Return string associated with this action
9
Q
Action Event Class int getModifiers()
A
Returns integer represent modifier keys user was pressing on keyboard
10
Q
Action Event Class Object getSource()
A
Returns obj that fired the event