15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.awt.event; 27 28 import java.awt.AWTEvent; 29 import java.awt.Event; 30 import java.lang.annotation.Native; 31 32 /** 33 * A semantic event which indicates that a component-defined action occurred. 34 * This high-level event is generated by a component (such as a 35 * <code>Button</code>) when 36 * the component-specific action occurs (such as being pressed). 37 * The event is passed to every <code>ActionListener</code> object 38 * that registered to receive such events using the component's 39 * <code>addActionListener</code> method. 40 * <p> 41 * <b>Note:</b> To invoke an <code>ActionEvent</code> on a 42 * <code>Button</code> using the keyboard, use the Space bar. 43 * <P> 44 * The object that implements the <code>ActionListener</code> interface 45 * gets this <code>ActionEvent</code> when the event occurs. The listener 46 * is therefore spared the details of processing individual mouse movements 47 * and mouse clicks, and can instead process a "meaningful" (semantic) 48 * event like "button pressed". 49 * <p> 50 * An unspecified behavior will be caused if the {@code id} parameter 51 * of any particular {@code ActionEvent} instance is not 52 * in the range from {@code ACTION_FIRST} to {@code ACTION_LAST}. 53 * 54 * @see ActionListener 55 * @see <a href="http://docs.oracle.com/javase/tutorial/uiswing/events/actionlistener.html">Tutorial: How to Write an Action Listener</a> 56 * 57 * @author Carl Quinn 58 * @since 1.1 59 */ 60 public class ActionEvent extends AWTEvent { 61 62 /** 63 * The shift modifier. An indicator that the shift key was held 64 * down during the event. 65 */ 120 */ 121 long when; 122 123 /** 124 * This represents the key modifier that was selected, 125 * and is used to determine the state of the selected key. 126 * If no modifier has been selected it will default to 127 * zero. 128 * 129 * @serial 130 * @see #getModifiers 131 */ 132 int modifiers; 133 134 /* 135 * JDK 1.1 serialVersionUID 136 */ 137 private static final long serialVersionUID = -7671078796273832149L; 138 139 /** 140 * Constructs an <code>ActionEvent</code> object. 141 * <p> 142 * This method throws an 143 * <code>IllegalArgumentException</code> if <code>source</code> 144 * is <code>null</code>. 145 * A <code>null</code> <code>command</code> string is legal, 146 * but not recommended. 147 * 148 * @param source The object that originated the event 149 * @param id An integer that identifies the event. 150 * For information on allowable values, see 151 * the class description for {@link ActionEvent} 152 * @param command A string that may specify a command (possibly one 153 * of several) associated with the event 154 * @throws IllegalArgumentException if <code>source</code> is null 155 * @see #getSource() 156 * @see #getID() 157 * @see #getActionCommand() 158 */ 159 public ActionEvent(Object source, int id, String command) { 160 this(source, id, command, 0); 161 } 162 163 /** 164 * Constructs an <code>ActionEvent</code> object with modifier keys. 165 * <p> 166 * This method throws an 167 * <code>IllegalArgumentException</code> if <code>source</code> 168 * is <code>null</code>. 169 * A <code>null</code> <code>command</code> string is legal, 170 * but not recommended. 171 * 172 * @param source The object that originated the event 173 * @param id An integer that identifies the event. 174 * For information on allowable values, see 175 * the class description for {@link ActionEvent} 176 * @param command A string that may specify a command (possibly one 177 * of several) associated with the event 178 * @param modifiers The modifier keys down during event 179 * (shift, ctrl, alt, meta). 180 * Passing negative parameter is not recommended. 181 * Zero value means that no modifiers were passed 182 * @throws IllegalArgumentException if <code>source</code> is null 183 * @see #getSource() 184 * @see #getID() 185 * @see #getActionCommand() 186 * @see #getModifiers() 187 */ 188 public ActionEvent(Object source, int id, String command, int modifiers) { 189 this(source, id, command, 0, modifiers); 190 } 191 192 /** 193 * Constructs an <code>ActionEvent</code> object with the specified 194 * modifier keys and timestamp. 195 * <p> 196 * This method throws an 197 * <code>IllegalArgumentException</code> if <code>source</code> 198 * is <code>null</code>. 199 * A <code>null</code> <code>command</code> string is legal, 200 * but not recommended. 201 * 202 * @param source The object that originated the event 203 * @param id An integer that identifies the event. 204 * For information on allowable values, see 205 * the class description for {@link ActionEvent} 206 * @param command A string that may specify a command (possibly one 207 * of several) associated with the event 208 * @param modifiers The modifier keys down during event 209 * (shift, ctrl, alt, meta). 210 * Passing negative parameter is not recommended. 211 * Zero value means that no modifiers were passed 212 * @param when A long that gives the time the event occurred. 213 * Passing negative or zero value 214 * is not recommended 215 * @throws IllegalArgumentException if <code>source</code> is null 216 * @see #getSource() 217 * @see #getID() 218 * @see #getActionCommand() 219 * @see #getModifiers() 220 * @see #getWhen() 221 * 222 * @since 1.4 223 */ 224 public ActionEvent(Object source, int id, String command, long when, 225 int modifiers) { 226 super(source, id); 227 this.actionCommand = command; 228 this.when = when; 229 this.modifiers = modifiers; 230 } 231 232 /** 233 * Returns the command string associated with this action. 234 * This string allows a "modal" component to specify one of several 235 * commands, depending on its state. For example, a single button might 236 * toggle between "show details" and "hide details". The source object 237 * and the event would be the same in each case, but the command string 238 * would identify the intended action. 239 * <p> 240 * Note that if a <code>null</code> command string was passed 241 * to the constructor for this <code>ActionEvent</code>, this 242 * this method returns <code>null</code>. 243 * 244 * @return the string identifying the command for this event 245 */ 246 public String getActionCommand() { 247 return actionCommand; 248 } 249 250 /** 251 * Returns the timestamp of when this event occurred. Because an 252 * ActionEvent is a high-level, semantic event, the timestamp is typically 253 * the same as an underlying InputEvent. 254 * 255 * @return this event's timestamp 256 * @since 1.4 257 */ 258 public long getWhen() { 259 return when; 260 } 261 262 /** | 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.awt.event; 27 28 import java.awt.AWTEvent; 29 import java.awt.Event; 30 import java.lang.annotation.Native; 31 32 /** 33 * A semantic event which indicates that a component-defined action occurred. 34 * This high-level event is generated by a component (such as a 35 * {@code Button}) when 36 * the component-specific action occurs (such as being pressed). 37 * The event is passed to every {@code ActionListener} object 38 * that registered to receive such events using the component's 39 * {@code addActionListener} method. 40 * <p> 41 * <b>Note:</b> To invoke an {@code ActionEvent} on a 42 * {@code Button} using the keyboard, use the Space bar. 43 * <P> 44 * The object that implements the {@code ActionListener} interface 45 * gets this {@code ActionEvent} when the event occurs. The listener 46 * is therefore spared the details of processing individual mouse movements 47 * and mouse clicks, and can instead process a "meaningful" (semantic) 48 * event like "button pressed". 49 * <p> 50 * An unspecified behavior will be caused if the {@code id} parameter 51 * of any particular {@code ActionEvent} instance is not 52 * in the range from {@code ACTION_FIRST} to {@code ACTION_LAST}. 53 * 54 * @see ActionListener 55 * @see <a href="http://docs.oracle.com/javase/tutorial/uiswing/events/actionlistener.html">Tutorial: How to Write an Action Listener</a> 56 * 57 * @author Carl Quinn 58 * @since 1.1 59 */ 60 public class ActionEvent extends AWTEvent { 61 62 /** 63 * The shift modifier. An indicator that the shift key was held 64 * down during the event. 65 */ 120 */ 121 long when; 122 123 /** 124 * This represents the key modifier that was selected, 125 * and is used to determine the state of the selected key. 126 * If no modifier has been selected it will default to 127 * zero. 128 * 129 * @serial 130 * @see #getModifiers 131 */ 132 int modifiers; 133 134 /* 135 * JDK 1.1 serialVersionUID 136 */ 137 private static final long serialVersionUID = -7671078796273832149L; 138 139 /** 140 * Constructs an {@code ActionEvent} object. 141 * <p> 142 * This method throws an 143 * {@code IllegalArgumentException} if {@code source} 144 * is {@code null}. 145 * A {@code null command} string is legal, 146 * but not recommended. 147 * 148 * @param source The object that originated the event 149 * @param id An integer that identifies the event. 150 * For information on allowable values, see 151 * the class description for {@link ActionEvent} 152 * @param command A string that may specify a command (possibly one 153 * of several) associated with the event 154 * @throws IllegalArgumentException if {@code source} is null 155 * @see #getSource() 156 * @see #getID() 157 * @see #getActionCommand() 158 */ 159 public ActionEvent(Object source, int id, String command) { 160 this(source, id, command, 0); 161 } 162 163 /** 164 * Constructs an {@code ActionEvent} object with modifier keys. 165 * <p> 166 * This method throws an 167 * {@code IllegalArgumentException} if {@code source} 168 * is {@code null}. 169 * A {@code null command} string is legal, 170 * but not recommended. 171 * 172 * @param source The object that originated the event 173 * @param id An integer that identifies the event. 174 * For information on allowable values, see 175 * the class description for {@link ActionEvent} 176 * @param command A string that may specify a command (possibly one 177 * of several) associated with the event 178 * @param modifiers The modifier keys down during event 179 * (shift, ctrl, alt, meta). 180 * Passing negative parameter is not recommended. 181 * Zero value means that no modifiers were passed 182 * @throws IllegalArgumentException if {@code source} is null 183 * @see #getSource() 184 * @see #getID() 185 * @see #getActionCommand() 186 * @see #getModifiers() 187 */ 188 public ActionEvent(Object source, int id, String command, int modifiers) { 189 this(source, id, command, 0, modifiers); 190 } 191 192 /** 193 * Constructs an {@code ActionEvent} object with the specified 194 * modifier keys and timestamp. 195 * <p> 196 * This method throws an 197 * {@code IllegalArgumentException} if {@code source} 198 * is {@code null}. 199 * A {@code null command} string is legal, 200 * but not recommended. 201 * 202 * @param source The object that originated the event 203 * @param id An integer that identifies the event. 204 * For information on allowable values, see 205 * the class description for {@link ActionEvent} 206 * @param command A string that may specify a command (possibly one 207 * of several) associated with the event 208 * @param modifiers The modifier keys down during event 209 * (shift, ctrl, alt, meta). 210 * Passing negative parameter is not recommended. 211 * Zero value means that no modifiers were passed 212 * @param when A long that gives the time the event occurred. 213 * Passing negative or zero value 214 * is not recommended 215 * @throws IllegalArgumentException if {@code source} is null 216 * @see #getSource() 217 * @see #getID() 218 * @see #getActionCommand() 219 * @see #getModifiers() 220 * @see #getWhen() 221 * 222 * @since 1.4 223 */ 224 public ActionEvent(Object source, int id, String command, long when, 225 int modifiers) { 226 super(source, id); 227 this.actionCommand = command; 228 this.when = when; 229 this.modifiers = modifiers; 230 } 231 232 /** 233 * Returns the command string associated with this action. 234 * This string allows a "modal" component to specify one of several 235 * commands, depending on its state. For example, a single button might 236 * toggle between "show details" and "hide details". The source object 237 * and the event would be the same in each case, but the command string 238 * would identify the intended action. 239 * <p> 240 * Note that if a {@code null} command string was passed 241 * to the constructor for this {@code ActionEvent}, this 242 * this method returns {@code null}. 243 * 244 * @return the string identifying the command for this event 245 */ 246 public String getActionCommand() { 247 return actionCommand; 248 } 249 250 /** 251 * Returns the timestamp of when this event occurred. Because an 252 * ActionEvent is a high-level, semantic event, the timestamp is typically 253 * the same as an underlying InputEvent. 254 * 255 * @return this event's timestamp 256 * @since 1.4 257 */ 258 public long getWhen() { 259 return when; 260 } 261 262 /** |