@Override public void setPressed(boolean b) { if ((isPressed() == b) || !isEnabled()) { return; } if (!b && isArmed()) { updateState(); } if (b) { stateMask |= PRESSED; } else { stateMask &= ~PRESSED; } fireStateChanged(); if (!isPressed() && isArmed()) { int modifiers = 0; AWTEvent currentEvent = EventQueue.getCurrentEvent(); if (currentEvent instanceof InputEvent) { modifiers = ((InputEvent) currentEvent).getModifiers(); } else if (currentEvent instanceof ActionEvent) { modifiers = ((ActionEvent) currentEvent).getModifiers(); } fireActionPerformed( new ActionEvent( this, ActionEvent.ACTION_PERFORMED, getActionCommand(), EventQueue.getMostRecentEventTime(), modifiers)); } }
/** * Perform the specified Action on the object * * @param i zero-based index of actions * @return true if the action was performed; otherwise false. */ public boolean doAccessibleAction(int i) { if (i == 0) { // Simulate a button click Toolkit.getEventQueue() .postEvent( new ActionEvent( MenuItem.this, ActionEvent.ACTION_PERFORMED, MenuItem.this.getActionCommand(), EventQueue.getMostRecentEventTime(), 0)); return true; } else { return false; } }
public void setPressed(boolean b) { if ((isPressed() == b) || !isEnabled()) { return; } if (b == false && isArmed()) { if (this.isSelected()) { if (label.isUnderline()) { label.setUnderline(false); setSelected(false); } else { label.setUnderline(true); } } else { setSelected(true); } } if (b) { stateMask |= PRESSED; } else { stateMask &= ~PRESSED; } fireStateChanged(); if (!isPressed() && isArmed()) { int modifiers = 0; AWTEvent currentEvent = EventQueue.getCurrentEvent(); if (currentEvent instanceof InputEvent) { modifiers = ((InputEvent) currentEvent).getModifiers(); } else if (currentEvent instanceof ActionEvent) { modifiers = ((ActionEvent) currentEvent).getModifiers(); } fireActionPerformed( new ActionEvent( this, ActionEvent.ACTION_PERFORMED, getActionCommand(), EventQueue.getMostRecentEventTime(), modifiers)); } }
/** * DOCUMENT ME! * * @param action DOCUMENT ME! */ protected void fireAction(ActionListener action) { int modifiers = 0; AWTEvent currentEvent = EventQueue.getCurrentEvent(); if (currentEvent instanceof InputEvent) { modifiers = ((InputEvent) currentEvent).getModifiers(); } else if (currentEvent instanceof ActionEvent) { modifiers = ((ActionEvent) currentEvent).getModifiers(); } ActionEvent e = new ActionEvent( getComponent(), ActionEvent.ACTION_PERFORMED, getComponent().getText(), EventQueue.getMostRecentEventTime(), modifiers); action.actionPerformed(e); }
/** Fire Action Event to listeners */ protected void fireActionPerformed() { int modifiers = 0; AWTEvent currentEvent = EventQueue.getCurrentEvent(); if (currentEvent instanceof InputEvent) modifiers = ((InputEvent) currentEvent).getModifiers(); else if (currentEvent instanceof ActionEvent) modifiers = ((ActionEvent) currentEvent).getModifiers(); ActionEvent ae = new ActionEvent( this, ActionEvent.ACTION_PERFORMED, "VNumber", EventQueue.getMostRecentEventTime(), modifiers); // Guaranteed to return a non-null array Object[] listeners = listenerList.getListenerList(); // Process the listeners last to first, notifying those that are interested in this event for (int i = listeners.length - 2; i >= 0; i -= 2) { if (listeners[i] == ActionListener.class) { ((ActionListener) listeners[i + 1]).actionPerformed(ae); } } } // fireActionPerformed