下面列出了怎么用java.awt.event.ActionEvent的API类实例代码及写法,或者点击链接到github查看源代码。
public void actionPerformed (ActionEvent ae) {
JComponent item = (JComponent) ae.getSource();
String actionCommand = (String) item.getClientProperty(KEY_ACTION);
String context = (String) item.getClientProperty(KEY_CONTAINERCTX);
getEngine().notifyWillPerform (actionCommand, context);
Action action = getEngine().getAction(context, actionCommand);
if (action.isEnabled()) {
ActionEvent event = new ActionEvent (item,
ActionEvent.ACTION_PERFORMED, actionCommand);
action.actionPerformed(event);
}
getEngine().notifyPerformed (actionCommand, context);
}
@Override
public void actionPerformed(ActionEvent e) {
final ResourceAssignment[] context = myContext.getResourceAssignments();
if (context != null && context.length > 0) {
Choice choice = myUIFacade.showConfirmationDialog(getI18n("msg23") + " " + StringUtils.getDisplayNames(context)
+ "?", getI18n("warning"));
if (choice == Choice.YES) {
myUIFacade.getUndoManager().undoableEdit(getLocalizedDescription(), new Runnable() {
@Override
public void run() {
deleteAssignments(context);
myUIFacade.refresh();
}
});
}
}
}
void dispatchEventImpl(AWTEvent e) {
EventQueue.setCurrentEventAndMostRecentTime(e);
Toolkit.getDefaultToolkit().notifyAWTEventListeners(e);
if (newEventsOnly ||
(parent != null && parent instanceof MenuComponent &&
((MenuComponent)parent).newEventsOnly)) {
if (eventEnabled(e)) {
processEvent(e);
} else if (e instanceof ActionEvent && parent != null) {
e.setSource(parent);
((MenuComponent)parent).dispatchEvent(e);
}
} else { // backward compatibility
Event olde = e.convertToOld();
if (olde != null) {
postEvent(olde);
}
}
}
/**
* Removes the selected item as long as it isn't root.
*/
public void actionPerformed(ActionEvent e) {
TreePath[] selected = getSelectedPaths();
if (selected != null && selected.length > 0) {
TreePath shallowest;
// The remove process consists of the following steps:
// 1 - find the shallowest selected TreePath, the shallowest
// path is the path with the smallest number of path
// components.
// 2 - Find the siblings of this TreePath
// 3 - Remove from selected the TreePaths that are descendants
// of the paths that are going to be removed. They will
// be removed as a result of their ancestors being
// removed.
// 4 - continue until selected contains only null paths.
while ((shallowest = findShallowestPath(selected)) != null) {
removeSiblings(shallowest, selected);
}
}
}
/**
* Handles user actions generated within the panel.
* @param event the event
*/
@Override
public void actionPerformed(ActionEvent event) {
String command = event.getActionCommand();
if (command.equals("BackgroundPaint")) {
attemptBackgroundPaintSelection();
}
else if (command.equals("OutlineStroke")) {
attemptOutlineStrokeSelection();
}
else if (command.equals("OutlinePaint")) {
attemptOutlinePaintSelection();
}
// else if (command.equals("Insets")) {
// editInsets();
// }
else if (command.equals("Orientation")) {
attemptOrientationSelection();
}
else if (command.equals("DrawLines")) {
attemptDrawLinesSelection();
}
else if (command.equals("DrawShapes")) {
attemptDrawShapesSelection();
}
}
public void DoAction(ActionEvent ev) {
//setTextoDica("");
if (diagramaAtual != null) {
diagramaAtual.DoAction(ev);
boolean eacao = false;
Acao ac = null;
if (((AbstractButton) ev.getSource()).getAction() instanceof Acao) {
eacao = true;
ac = (Acao) ((AbstractButton) ev.getSource()).getAction();
try {
setTextoDica(null, ac.getValue(Action.SHORT_DESCRIPTION).toString());
} finally {
}
}
if (ev.getSource() instanceof JMenuItem) {
if (eacao) {
controler.SelecioneForAction(ac);
}
}
}
}
@Override
public void actionPerformed(final ActionEvent e) {
final IdeFocusManager fm = IdeFocusManager.findInstanceByContext(myContext);
final ActionCallback typeAhead = new ActionCallback();
final String id = ActionManager.getInstance().getId(myAction.getAction());
if (id != null) {
FeatureUsageTracker.getInstance().triggerFeatureUsed("context.menu.click.stats." + id.replace(' ', '.'));
}
fm.typeAheadUntil(typeAhead, getText());
fm.runOnOwnContext(myContext, () -> {
final AnActionEvent event =
new AnActionEvent(new MouseEvent(ActionMenuItem.this, MouseEvent.MOUSE_PRESSED, 0, e.getModifiers(), getWidth() / 2, getHeight() / 2, 1, false),
myContext, myPlace, myPresentation, ActionManager.getInstance(), e.getModifiers(), true, false);
final AnAction menuItemAction = myAction.getAction();
if (ActionUtil.lastUpdateAndCheckDumb(menuItemAction, event, false)) {
ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
actionManager.fireBeforeActionPerformed(menuItemAction, myContext, event);
fm.doWhenFocusSettlesDown(typeAhead::setDone);
ActionUtil.performActionDumbAware(menuItemAction, event);
actionManager.queueActionPerformedEvent(menuItemAction, myContext, event);
}
else {
typeAhead.setDone();
}
});
}
@Messages("TIT_CustomGradle=Select Gradle Distribution")
private void btUseCustomGradleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btUseCustomGradleActionPerformed
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle(Bundle.TIT_CustomGradle());
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setFileHidingEnabled(false);
String path = tfUseCustomGradle.getText();
if (path == null || path.trim().length() == 0) {
path = GradleSettings.getDefault().getGradleUserHome().getAbsolutePath();
}
if (path.length() > 0) {
File f = new File(path);
if (f.exists()) {
chooser.setSelectedFile(f);
}
}
if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
File distDir = chooser.getSelectedFile();
tfUseCustomGradle.setText(distDir.getAbsolutePath());
}
}
/**
* Constructor
* @param tool tool to execute task and log messages in status window
* @param list list of domain files that have changes
*/
public ChangedFilesDialog(PluginTool tool, ArrayList<DomainFile> list) {
super("Save Changed Files?", true);
this.tool = tool;
this.fileList = list;
addWorkPanel(buildMainPanel());
JButton saveButton = new JButton("Save");
saveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
save();
}
});
saveButton.setToolTipText("Save files that have selected check boxes");
addButton(saveButton);
addCancelButton();
}
private void initComponents(){
jfxPanel = new JFXPanel();
createScene();
setLayout(new BorderLayout());
add(jfxPanel, BorderLayout.CENTER);
swingButton = new JButton();
swingButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Platform.runLater(new Runnable() {
@Override
public void run() {
webEngine.reload();
}
});
}
});
swingButton.setText("Reload");
add(swingButton, BorderLayout.SOUTH);
}
/**
* Creates new form TroopTableTab
*
* @param pTroopSet
* @param pActionListener
*/
public TroopTableTab(String pTroopSet, final ActionListener pActionListener) {
actionListener = pActionListener;
sTroopSet = pTroopSet;
initComponents();
jScrollPane1.setViewportView(jxTroopTable);
mSupportDetailsDialog = new SupportDetailsDialog(DSWorkbenchTroopsFrame.getSingleton(), true);
mTroopDetailsDialog = new TroopDetailsDialog(DSWorkbenchTroopsFrame.getSingleton(), true);
if (!KEY_LISTENER_ADDED) {
KeyStroke delete = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false);
KeyStroke bbCopy = KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK, false);
jxTroopTable.registerKeyboardAction(pActionListener, "Delete", delete, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
jxTroopTable.registerKeyboardAction(pActionListener, "BBCopy", bbCopy, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
jxTroopTable.getActionMap().put("find", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
pActionListener.actionPerformed(new ActionEvent(jxTroopTable, 0, "Find"));
}
});
KEY_LISTENER_ADDED = true;
}
jxTroopTable.getSelectionModel().addListSelectionListener(TroopTableTab.this);
// jTroopAmountList.setCellRenderer(new TroopAmountListCellRenderer());
}
public void actionPerformed(ActionEvent event) {
JTextComponent target = getTextComponent(event);
if (target != null) {
String line = SyntaxUtil.getLine(target);
/**
* Perform Smart Indentation: pos must be on a line: this method will
* use the previous lines indentation (number of spaces before any non-space
* character or end of line) and return that as the prefix.
*/
String indent = "";
if (line != null && line.length() > 0) {
int i = 0;
while (i < line.length() && line.charAt(i) == ' ') {
i++;
}
indent = line.substring(0, i);
}
target.replaceSelection("\n" + indent);
}
}
/**
* Invoked when an action occurs.
*/
public void actionPerformed( final ActionEvent e ) {
StringBuffer completeText = new StringBuffer();
final int[] selectedRows = expressionsTable.getSelectedRows();
for ( int i = 0; i < selectedRows.length; i++ ) {
final int selectedRow = selectedRows[ i ];
final int modelRow = expressionsTable.convertRowIndexToModel( selectedRow );
final EditableExpressionMetaData data = metaData[ modelRow ];
data.sort( expressionsTableModel.getLocale() );
final String text = data.printBundleText( expressionsTableModel.getLocale() );
System.out.println( "# Printing metadata for " + metaData[ modelRow ].getName() );
System.out.println( text );
completeText.append( "# Printing metadata for " + metaData[ modelRow ].getName() );
completeText.append( "\n" );
completeText.append( text );
}
dialog.showText( completeText.toString() );
}
private void addAnimationObjectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addAnimationObjectActionPerformed
AnimationObjectEditor editor = new AnimationObjectEditor(res, null, getValue(duration));
editor.setStartTime(timeline.getValue());
int ok = JOptionPane.showConfirmDialog(this, editor, "Add", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
if(ok == JOptionPane.OK_OPTION) {
((AnimationObjectTableModel)animationObjectList.getModel()).addElement(editor.getAnimationObject());
Timeline t = (Timeline)res.getImage(name);
AnimationObject[] animations = new AnimationObject[t.getAnimationCount() + 1];
for(int iter = 0 ; iter < animations.length - 1 ; iter++) {
animations[iter] = t.getAnimation(iter);
}
animations[animations.length - 1] = editor.getAnimationObject();
Timeline nt = Timeline.createTimeline(getValue(duration), animations,
new com.codename1.ui.geom.Dimension(getValue(width), getValue(height)));
nt.setPause(t.isPause());
nt.setTime(t.getTime());
setImage(nt);
}
}
public void testCanTCGarbageCollectWhenActionInMapAndAssignLookup() {
TopComponent tc = new TopComponent();
class CAA extends AbstractAction implements
ContextAwareAction {
public void actionPerformed(ActionEvent arg0) {
throw new UnsupportedOperationException("Not supported yet.");
}
public Action createContextAwareInstance(Lookup actionContext) {
return this;
}
}
tc.associateLookup(Lookups.fixed(tc.getActionMap(), tc));
ContextAwareAction del = new CAA();
ContextAwareAction context = Actions.context(Integer.class, true, true, del, null, "DisplayName", null, true);
Action a = context.createContextAwareInstance(tc.getLookup());
tc.getActionMap().put("key", a);
WeakReference<Object> ref = new WeakReference<Object>(tc);
tc = null;
a = null;
del = null;
context = null;
assertGC("Can the component GC?", ref);
}
private void addMenuItemListener(final JCheckBoxMenuItem menuItem) {
final boolean[] internalChange = new boolean[1];
menuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
if (internalChange[0]) return;
final int column = Integer.parseInt(e.getActionCommand());
if (column == 5 && !fieldsListTableModel.isRealColumnVisible(column)) {
BrowserUtils.performTask(new Runnable() {
public void run() {
final int retainedSizesState = fieldsBrowserController.getInstancesControllerHandler().
getHeapFragmentWalker().computeRetainedSizes(false, true);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if (retainedSizesState != HeapFragmentWalker.RETAINED_SIZES_COMPUTED) {
internalChange[0] = true;
menuItem.setSelected(!menuItem.isSelected());
internalChange[0] = false;
} else {
fieldsListTableModel.setRealColumnVisibility(column,
!fieldsListTableModel.isRealColumnVisible(column));
fieldsListTable.createDefaultColumnsFromModel();
fieldsListTable.updateTreeTableHeader();
setColumnsData();
}
}
});
}
});
} else {
fieldsListTableModel.setRealColumnVisibility(column,
!fieldsListTableModel.isRealColumnVisible(column));
fieldsListTable.createDefaultColumnsFromModel();
fieldsListTable.updateTreeTableHeader();
setColumnsData();
}
}
});
}
@Override
public void actionPerformed(ActionEvent e) {
if (JOptionPane.showConfirmDialog(null, GlobalResourcesManager
.getString("DeleteActiveElementsDialog.Warning"),
GlobalResourcesManager.getString("ConfirmMessage.Title"),
JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION)
return;
component.deleteElements();
}
@Override
public void loggedActionPerformed(ActionEvent e) {
ResultObject referenced = ioObject.get();
if (referenced != null) {
RapidMinerGUI.getMainFrame().getResultDisplay().showResult(referenced);
}
}
protected WebDynamicMenu createMenu ()
{
final WebDynamicMenu menu = new WebDynamicMenu ();
menu.setType ( ( DynamicMenuType ) type.getSelectedItem () );
menu.setHideType ( ( DynamicMenuType ) hidingType.getSelectedItem () );
menu.setRadius ( Integer.parseInt ( radius.getText () ) );
menu.setFadeStepSize ( 0.07f );
final int items = Integer.parseInt ( amount.getText () );
for ( int i = 1; i <= items; i++ )
{
final ImageIcon icon = WebLookAndFeel.getIcon ( 24 );
final ActionListener action = new ActionListener ()
{
@Override
public void actionPerformed ( final ActionEvent e )
{
System.out.println ( icon );
}
};
final WebDynamicMenuItem item = new WebDynamicMenuItem ( icon, action );
item.setMargin ( new Insets ( 8, 8, 8, 8 ) );
menu.addItem ( item );
}
return menu;
}
private void fireActionEvent(Color color) {
Object[] listeners = listenerList.getListenerList();
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == ActionListener.class) {
ActionEvent actionEvent = new ActionEvent(button, ActionEvent.ACTION_PERFORMED, color.toString());
((ActionListener) listeners[i + 1]).actionPerformed(actionEvent);
}
}
}
private JPanel createButtonPanel() {
// Set up the other controls
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
JButton okButton = new JButton("Ok");
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(false);
}
});
getRootPane().setDefaultButton(okButton);
buttonPanel.add(okButton);
return buttonPanel;
}
/** Creates the ui. */
private void createUI() {
scaleGroupPanel = new JPanel();
FlowLayout flowLayout = (FlowLayout) scaleGroupPanel.getLayout();
flowLayout.setVgap(0);
flowLayout.setHgap(0);
scaleGroupPanel.setBorder(
BorderFactory.createTitledBorder(
Localisation.getString(ScaleTool.class, "ScaleTool.scale")));
scaleButton =
new ToolButton(
Localisation.getString(ScaleTool.class, "ScaleTool.scale"),
"tool/scaletool.png");
scaleGroupPanel.add(scaleButton);
scaleButton.setEnabled(false);
scaleButton.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
ScaleToolPanel scalePanel = new ScaleToolPanel(application);
scalePanel.populate(sldDataList);
scalePanel.setVisible(true);
}
});
scaleGroupPanel.setPreferredSize(new Dimension(PANEL_WIDTH, ToolPanel.TOOL_PANEL_HEIGHT));
}
public JButton create(final Runnable onClose) {
JButton close = CloseButtonFactory.createBigCloseButton();
if (onClose != null) close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { onClose.run(); }
});
return close;
}
public BooleanControlButtonModel(BooleanControl control) {
this.control = control;
this.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setSelected(!isSelected());
}
});
}
@Override
public void actionPerformed(ActionEvent actionEvent) {
PetriNetController controller = applicationController.getActivePetriNetController();
UndoManager manager = controller.getUndoManager();
manager.redo();
this.setEnabled(manager.canRedo());
undoAction.setEnabled(manager.canUndo());
}
@Override
public void actionPerformed(ActionEvent e)
{
List<?> data = purchasedTable.getSelectedData();
if (data != null)
{
for (Object object : data)
{
character.removePurchasedEquipment((EquipmentFacade) object, 1, false);
}
availableTable.refilter();
}
}
public void actionPerformed(ActionEvent e) {
JColorWell well = (JColorWell) e.getSource();
Window owner = SwingUtilities.getWindowAncestor(well);
Color newValue = JColorPicker.showDialog(owner, well
.getColorSelectionModel().getSelectedColor());
if (newValue != null) {
well.getColorSelectionModel().setSelectedColor(newValue);
}
}
/**
* This provides the feature which is like in Eclipse when you control
* click on an identifier it takes you to the file that contains the
* identifier (method, class, etc) definition. Similarly, ctrl-clicking
* on an identifier in the SQL editor will invoke the view object at
* cursor in object tree action.
*/
@Override
public void mouseClicked(MouseEvent e) {
if (e.isControlDown() && e.getClickCount() == 1) {
final Action a =
_app.getActionCollection().get(ViewObjectAtCursorInObjectTreeAction.class);
GUIUtils.processOnSwingEventThread(new Runnable() {
public void run() {
a.actionPerformed(new ActionEvent(this, 1, "ViewObjectAtCursorInObjectTreeAction"));
}
});
}
}
private void removeCapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeCapActionPerformed
int[] rows = capTable.getSelectedRows();
if (rows != null) {
DefaultTableModel model = (DefaultTableModel) capTable.getModel();
for (int i = rows.length - 1; i >= 0; i--) {
model.removeRow(rows[i]);
}
}
}
/**
* This method initializes jComboBox1
*
* @return javax.swing.JComboBox
*/
private JComboBox<String> getJTagComboBox() {
if (jTagComboBox == null) {
jTagComboBox = new JComboBox<String>(tagNames);
jTagComboBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
JTextArea ta = getJTemplateTextArea();
ta.insert("{" + (String) jTagComboBox.getSelectedItem() +
"}",ta.getCaretPosition());
}
});
}
return jTagComboBox;
}