getSource与getActionCommand的区别

来源:互联网 发布:java 断点 编辑:程序博客网 时间:2024/06/08 02:45

getSource与getActionCommand的区别

 
转载

getSource()
Returns:
The object on which the Event initially occurred.
依赖于事件对象

getActionCommand()

Returns the command name of the action event fired by this button. If the command name is null (default) then this method returns the label of the button.
依赖于按钮上的字符串

getSource得到的组件的名称,而getActionCommand得到的是标签。
如:Button bt=new Button("buttons");
      用getSource得到的是bt 而用getActionCommand得到的是:buttons

0 0