yellowButton.addActionListener(this);
addActionListener 方法中的 (this) 指的是什么。有人可以告诉我 actionListener 方法是如何工作的吗?
最佳答案
this
是当前对象。它必须实现 ActionListener 接口(interface)。
这通常用于将所有相关代码集中在一处。但您也可以使用yellowButton.addActionListener(new ButtonActionListener())
,其中ButtonActionListener
是您的另一个类。
实现 ActionListener
的类应指定操作发生时会发生什么。
关于java - 事件处理问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6312139/