Creating an Action : Action « Swing Event « Java Tutorial

Home
Java Tutorial
1.Language
2.Data Type
3.Operators
4.Statement Control
5.Class Definition
6.Development
7.Reflection
8.Regular Expressions
9.Collections
10.Thread
11.File
12.Generics
13.I18N
14.Swing
15.Swing Event
16.2D Graphics
17.SWT
18.SWT 2D Graphics
19.Network
20.Database
21.Hibernate
22.JPA
23.JSP
24.JSTL
25.Servlet
26.Web Services SOA
27.EJB3
28.Spring
29.PDF
30.Email
31.J2ME
32.J2EE Application
33.XML
34.Design Pattern
35.Log
36.Security
37.Apache Common
38.Ant
39.JUnit
Java Tutorial » Swing Event » Action 




import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.KeyStroke;

public class Main {
  public static void main(String[] argvthrows Exception {
    final Action action = new AbstractAction("Action Name") {
      {
        putValue(Action.SHORT_DESCRIPTION, "Tool Tip Text");

        putValue(Action.LONG_DESCRIPTION, "Help Text");

        Icon icon = new ImageIcon("icon.gif");
        putValue(Action.SMALL_ICON, icon);

        putValue(Action.MNEMONIC_KEY, new Integer(java.awt.event.KeyEvent.VK_A));
        putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control F2"));
      }
      public void actionPerformed(ActionEvent evt) {
        System.out.println("action");
      }
    };

    JButton button = new JButton(action);
  }
}














15.3.Action
15.3.1.AbstractAction Lookup Property Keys
15.3.2.Creating an Action
15.3.3.Action Usage ExampleAction Usage Example
15.3.4.extends AbstractActionextends AbstractAction
15.3.5.Disable an ActionDisable an Action
15.3.6.Get and set Action Command
15.3.7.Register action
15.3.8.ActionMap javax.swing.JComponent.getActionMap()
15.3.9.Map actions with keystrokes
15.3.10.Enabling an Action
15.3.11.Listing the Actions in a Component
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.