JavaTM 2 Platform
Standard Ed. 6

javax.swing
类 AbstractAction

java.lang.Object
  继承者 javax.swing.AbstractAction
所有已实现的接口:
ActionListener, Serializable, Cloneable, EventListener, Action
直接已知子类:
BasicDesktopPaneUI.CloseAction, BasicDesktopPaneUI.MaximizeAction, BasicDesktopPaneUI.MinimizeAction, BasicDesktopPaneUI.NavigateAction, BasicDesktopPaneUI.OpenAction, BasicFileChooserUI.ApproveSelectionAction, BasicFileChooserUI.CancelSelectionAction, BasicFileChooserUI.ChangeToParentDirectoryAction, BasicFileChooserUI.GoHomeAction, BasicFileChooserUI.NewFolderAction, BasicFileChooserUI.UpdateAction, BasicInternalFrameTitlePane.CloseAction, BasicInternalFrameTitlePane.IconifyAction, BasicInternalFrameTitlePane.MaximizeAction, BasicInternalFrameTitlePane.MoveAction, BasicInternalFrameTitlePane.RestoreAction, BasicInternalFrameTitlePane.SizeAction, BasicSliderUI.ActionScroller, BasicTreeUI.TreeCancelEditingAction, BasicTreeUI.TreeHomeAction, BasicTreeUI.TreeIncrementAction, BasicTreeUI.TreePageAction, BasicTreeUI.TreeToggleAction, BasicTreeUI.TreeTraverseAction, MetalFileChooserUI.DirectoryComboBoxAction, TextAction

public abstract class AbstractAction
extends Object
implements Action, Cloneable, Serializable

此类提供 JFC Action 接口的默认实现。它定义了一些标准行为,比如 Action 对象属性(icon、text 和 enabled)的 get 和 set 方法。开发人员只需为此抽象类创建子类并定义 actionPerformed 方法即可。

警告:此类的已序列化对象与以后的 Swing 版本不兼容。当前序列化支持适用于短期存储,或适用于在运行相同 Swing 版本的应用程序之间进行 RMI(Remote Method Invocation,远程方法调用)。从 1.4 版本开始,已在 java.beans 包中添加了支持所有 JavaBeansTM 长期存储的功能。请参见 XMLEncoder

另请参见:
Action

字段摘要
protected  SwingPropertyChangeSupport changeSupport
          如果已经注册了任意 PropertyChangeListener,则 changeSupport 字段负责描述它们。
protected  boolean enabled
          指定是否启用操作;默认值为 true。
 
从接口 javax.swing.Action 继承的字段
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, DISPLAYED_MNEMONIC_INDEX_KEY, LARGE_ICON_KEY, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SELECTED_KEY, SHORT_DESCRIPTION, SMALL_ICON
 
构造方法摘要
AbstractAction()
          用默认描述字符串和默认图标定义一个 Action 对象。
AbstractAction(String name)
          用指定描述字符串和默认图标定义一个 Action 对象。
AbstractAction(String name, Icon icon)
          用指定描述字符串和指定图标定义一个 Action 对象。
 
方法摘要
 void addPropertyChangeListener(PropertyChangeListener listener)
          向侦听器列表添加一个 PropertyChangeListener
protected  Object clone()
          复制抽象操作。
protected  void firePropertyChange(String propertyName, Object oldValue, Object newValue)
          支持报告绑定 (bound) 属性的改变。
 Object[] getKeys()
          返回 Object 的数组,这些对象是一些已经为其设置此 AbstractAction 值的键,如果没有已经设置该值的键,则返回 null
 PropertyChangeListener[] getPropertyChangeListeners()
          返回使用 addPropertyChangeListener() 添加到此 AbstractAction 中的所有 PropertyChangeListener 组成的数组。
 Object getValue(String key)
          获得与指定键关联的 Object
 boolean isEnabled()
          如果启用该操作,则返回 true。
 void putValue(String key, Object newValue)
          设置与指定键关联的 Value
 void removePropertyChangeListener(PropertyChangeListener listener)
          从侦听器列表中移除一个 PropertyChangeListener
 void setEnabled(boolean newValue)
          启用或禁用该操作。
 
从类 java.lang.Object 继承的方法
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
从接口 java.awt.event.ActionListener 继承的方法
actionPerformed
 

字段详细信息

enabled

protected boolean enabled
指定是否启用操作;默认值为 true。


changeSupport

protected SwingPropertyChangeSupport changeSupport
如果已经注册了任意 PropertyChangeListener,则 changeSupport 字段负责描述它们。

构造方法详细信息

AbstractAction

public AbstractAction()
用默认描述字符串和默认图标定义一个 Action 对象。


AbstractAction

public AbstractAction(String name)
用指定描述字符串和默认图标定义一个 Action 对象。


AbstractAction

public AbstractAction(String name,
                      Icon icon)
用指定描述字符串和指定图标定义一个 Action 对象。

方法详细信息

getValue

public Object getValue(String key)
获得与指定键关联的 Object

指定者:
接口 Action 中的 getValue
参数:
key - 包含指定 key 的字符串
返回:
用此键存储的绑定 Object;如果没有键,则将返回 null
另请参见:
Action.getValue(java.lang.String)

putValue

public void putValue(String key,
                     Object newValue)
设置与指定键关联的 Value

指定者:
接口 Action 中的 putValue
参数:
key - 标识所存储对象的 String
newValue - 将使用此键存储的 Object
另请参见:
Action.putValue(java.lang.String, java.lang.Object)

isEnabled

public boolean isEnabled()
如果启用该操作,则返回 true。

指定者:
接口 Action 中的 isEnabled
返回:
如果启用该操作,则返回 true;否则返回 false
另请参见:
Action.isEnabled()

setEnabled

public void setEnabled(boolean newValue)
启用或禁用该操作。

指定者:
接口 Action 中的 setEnabled
参数:
newValue - 为 true 表示启用该操作,为 false 表示禁用该操作
另请参见:
Action.setEnabled(boolean)

getKeys

public Object[] getKeys()
返回 Object 的数组,这些对象是一些已经为其设置此 AbstractAction 值的键,如果没有已经设置该值的键,则返回 null

返回:
一个键对象数组,如果没有已经设置好值的键,则返回 null
从以下版本开始:
1.3

firePropertyChange

protected void firePropertyChange(String propertyName,
                                  Object oldValue,
                                  Object newValue)
支持报告绑定 (bound) 属性的改变。当改变了绑定属性时可调用此方法,它将向所有已注册的 PropertyChangeListener 发送相应的 PropertyChangeEvent


addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
向侦听器列表添加一个 PropertyChangeListener。该侦听器是为所有属性注册的。

在响应对绑定属性(例如 setFontsetBackgroundsetForeground)的设置时,将触发一个 PropertyChangeEvent。注意,如果当前组件将继承其容器的前景、背景或字体,则在响应所继承属性中的更改时不会触发任何事件。

指定者:
接口 Action 中的 addPropertyChangeListener
参数:
listener - 要添加的 PropertyChangeListener
另请参见:
Action.addPropertyChangeListener(java.beans.PropertyChangeListener)

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
从侦听器列表中移除一个 PropertyChangeListener。此方法移除了一个为所有属性注册的 PropertyChangeListener

指定者:
接口 Action 中的 removePropertyChangeListener
参数:
listener - 要移除的 PropertyChangeListener
另请参见:
Action.removePropertyChangeListener(java.beans.PropertyChangeListener)

getPropertyChangeListeners

public PropertyChangeListener[] getPropertyChangeListeners()
返回使用 addPropertyChangeListener() 添加到此 AbstractAction 中的所有 PropertyChangeListener 组成的数组。

返回:
添加的所有 PropertyChangeListener,如果没有添加侦听器,则返回一个空数组
从以下版本开始:
1.4

clone

protected Object clone()
                throws CloneNotSupportedException
复制抽象操作。此方法给出了它自己的键/值列表的副本,该副本不能通过 Object.clone() 为您处理。

覆盖:
Object 中的 clone
返回:
此实例的一个副本。
抛出:
CloneNotSupportedException - 如果对象的类不支持 Cloneable 接口,则重写 clone 方法的子类也会抛出此异常,以指示无法复制某个实例。
另请参见:
Cloneable

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见

版权所有 2008 Sun Microsystems, Inc. 保留所有权利。请遵守GNU General Public License, version 2 only