JAVA-getComponent()与getSource()

来源:互联网 发布:手机建站cms 编辑:程序博客网 时间:2024/06/11 01:30

两个方法都是获取发生事件的事件源对象,区别也许是返回的类型不同,如果是getSource()需要强制类型转换为Component 对象;而getComponent()无需转换;
API的说明如下:
类ComponentEvent
getComponent()返回发起事件的 Component 对象,如果该对象不是一个 Component,则返回 null。
类EventObject
getSource()返回最初发生 Event 的对象。

原创粉丝点击