Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML
 
 
Hot Web Programming Job

 

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


 

Java Tutorials

Core Java
JSP
Servlet
JDBC
Hibernate
Struts 1
Struts 2
JSF
Spring
J2EE
J2ME
Web Services
Ajax
Dojo
MySQL
Latest Comments
Contents are not d
Please Use JAVA no
hidden tag in orku
Getting good knowl
Why the output on
  All Comments...
 

 

 
Struts Tutorials
*Stuts TOC
*Apache Struts Introduction
* Struts Controller
* Struts Action Class
* Struts ActionFrom Class
* Using Struts HTML Tags
*Struts Validator Framework    
*Client Side Address Validation    
*Struts Tiles
*tiles-defs.xml
*Struts DynaActionForm
*Struts File Upload
*Struts DataSource
*AGGREGATING ACTIONS
*Internationalization
Struts Resources
*Struts Books
*Struts Articles
*Struts Frameworks
*Struts IDE
*Struts Alternative
*Struts Links
*Struts Presentations
*Struts Projects
*Struts Software
*Struts Reference
*Struts Resources
*Other Struts Tutorial
Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Have tutorials?
Add your tutorial to our Java Resource and get tons of hits.

We offer free hosting for your tutorials. and exposure for thousands of readers. drop a mail
roseindia_net@yahoo.com
 
   

 
Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

Java Notes

Action, AbstractAction

The javax.swing.Action interface, and the corresponding class, javax.swing.AbstractAction, provide a useful mechanism to implement action listeners that can be shared and coordinated.

  • Actions can be used with most buttons, including toobox buttons and menu items, text fields, etc.
  • They can be shared with all controls which do the same thing.
  • Actions can be dis-/enabled, and they will then dis-/enable all corresponding controls.
  • They can specify text, icons, tooltip text, accelerator, and mnemonic keys.

Subclassing. You must subclass AbstractAction (the hint is the word "abstract" in the class name). The minimum you need to do is override actionPerformed to specify what you want the Action to do. See examples below.

AbstractAction constructors, methods, and fields

Constructors
act = new AbstractAction(String name); Specifies name for buttons, etc.
act = new AbstractAction(String name, Icon smallIcon); Specifies name and an icon (eg, that will appear on a toolbar buttons).
Some Methods
b = act.isEnabled() Returns true if this Action is enabled.
 act.setEnabled(boolean enabled) Sets the status of this Action.
 act.putValue(String key, Object value) Sets the value of property key to value.
obj = act.getValue(String key) Gets the value of property key.
Some Property Fields (use putValue() to explicitly set these fields)
 ACCELERATOR_KEYAccelerator key.
 MNEMONIC_KEY Mnemonic key.
 NAME Name for buttons and menu items.
 SHORT_DESCRIPTIONUsed as tooltip text.
 SMALL_ICON Used for toolbars.

Usage

Actions can be used directly in the add() method of some containers (eg, menus and toolbars), or in constructors for buttons and menu items.

fileMenu.add(exitAction);  // Add directly to menu.  Uses Action's text, icon.

If you don't want all the functionality of an Action, create the desired component from the Action, then modify it.

JMenuItem exitItem = new JMenuItem(exitAction);  // Use to create component.
exitItem.setIcon(null);                          // Modify to suppress the icon.
fileMenu.add(exitItem);

Example - Simple anonymous class

  1 
  2 
  3 
  4 
  5 
  6 
  7 
Action openAction = new AbstractAction("Open...") {
    public void actionPerformed(ActionEvent e) {
        openFile();  // Do what you want here.
    }
};
. . .
fileMenu.add(openAction);  // Add action to menu

The Simple Editor example shows the use of anonymous subclassing.

Example - Defining subclass to get additional functionality

  1 
  2 
  3 
  4 
  5 
  6 
  7 
  8 
  9 
 10 
 11 
 12 
 13 
 14 
 15 
 16 
 17 
Action openAction = new OpenAction("Open...", folderIcon, "Open file.", KeyEvent.VK_O);
. . .
fileMenu.add(openAction);  // Add action to menu
. . .
class OpenAction extends AbstractAction {
    //-- Define a constructor which takes parameters you want to set.
    public OpenAction(String text, ImageIcon icon, String tooltip, int mnemonic) {
        super(text, icon); //  AbstractAction constructor takes only two params.
        putValue(SHORT_DESCRIPTION, tooltip);  // Will appear as tooltip text.
        putValue(MNEMONIC_KEY, new Integer(mnemonic));
    }
    
    //-- Override actionPerformed to do what you want.
    public void actionPerformed(ActionEvent e) {
        openFile();  // Do what you want here.
    }
}

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.