Java setActionCommand设置的动作命令是什么?
在Swing示例代码中,我遇到了setActionCommand方法。Java的引用仅说明它“为该组件设置操作命令”。什么是操作命令?为什么需要设置它?事实上,Java setActionCommand设置的动作命令是什么?,java,swing,awt,actionlistener,Java,Swing,Awt,Actionlistener,在Swing示例代码中,我遇到了setActionCommand方法。Java的引用仅说明它“为该组件设置操作命令”。什么是操作命令?为什么需要设置它?事实上,JButton将指定的操作命令重定向到按钮模型。下面是转发到按钮模型的方法,带有注释 /** * Sets the action command string that gets sent as part of the * <code>ActionEvent</code> when the
JButton
将指定的操作命令重定向到按钮模型。下面是转发到按钮模型的方法,带有注释
/**
* Sets the action command string that gets sent as part of the
* <code>ActionEvent</code> when the button is triggered.
*
* @param s the <code>String</code> that identifies the generated event
* @see #getActionCommand
* @see java.awt.event.ActionEvent#getActionCommand
*/
public void setActionCommand(String s)
因此,在您的ActionListener
中,当您获得ActionEvent
时,您可以检查getActionCommand()
以区分单击了哪个按钮