Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Action Interface  RSS feed

 
Manish Khurana
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not understand the following. It is from page 37 of The Definitive Guide to
Java Swing
Third Edition
JOHN ZUKOWSKI.

I do not understand how can a interface implement another interface. I thought classes did that or i been going crazy. also I do not understand the Action inter


Action Interface
The Action interface is an extension to the ActionListener interface that�s very flexible for
defining shared event handlers independent of the components that act as the triggering agents.
The interface implements ActionListener and defines a lookup table data structure whose
keys act as bound properties. Then, when an Action is associated with a component, these
display properties are automatically carried over to it. The following is the interface definition:
public interface Action implements ActionListener {
// Constants
public final static String ACCELERATOR_KEY;
public final static String ACTION_COMMAND_KEY;
public final static String DEFAULT;
public final static String LONG_DESCRIPTION;
public final static String MNEMONIC_KEY;
public final static String NAME;
public final static String SHORT_DESCRIPTION;
public final static String SMALL_ICON;
// Listeners
public void addPropertyChangeListener(PropertyChangeListener listener);
public void removePropertyChangeListener(PropertyChangeListener listener);
// Properties
public boolean isEnabled();
public void setEnabled(boolean newValue);
// Other methods
public Object getValue(String key);
public void putValue(String key, Object value);
}
Because Action is merely an interface, the Swing libraries offer a class to implement the
interface. That class is AbstractAction.
AbstractAction Class
The AbstractAction class provides a default implementation of the Action
 
Brian Cole
Author
Ranch Hand
Posts: 937
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Manish Khurana:
I do not understand how can a interface implement another interface. I thought classes did that or i been going crazy.


Classes can implement interfaces, but interfaces can extend other interfaces. See JLS �9.1.3: Superinterfaces and Subinterfaces.

Action Interface
The Action interface is an extension to the ActionListener interface that�s very flexible for
defining shared event handlers independent of the components that act as the triggering agents.
The interface implements ActionListener and defines a lookup table data structure whose
keys act as bound properties. Then, when an Action is associated with a component, these
display properties are automatically carried over to it. The following is the interface definition:

public interface Action implements ActionListener {


If you take a look at the source code, you'll see that the actual definition is:

public interface Action extends ActionListener {

So Action is an interface that extends the ActionListener interface. Alternatively, Action is a direct subinterface of ActionListener, and ActionListener is the direct superinterface of Action.

If class FooAction implements the Action interface, then it also implements the ActionListener interface.

[edit: Though Action is part of the Swing GUI, this isn't really a Swing topic.]
[ February 22, 2008: Message edited by: Brian Cole ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!