继续在看Java Tutorial,不过已经到了GUI了,呵呵!~在"Introduction to Event Listeners"中,看到了JAVA的事件监听机制。实现事件监听机制,需要有如下三件事情:
1、In the declaration for the event handler class, one line of code specifies that the class either implements a listener interface or extends a class that implements a listener interface. For example: public class MyClass implements ActionListener {
2、Another line of code registers an instance of the event handler class as a listener on one or more components. For example: someComponent.addActionListener(instanceOfMyClass);
3、The event handler class has code that implements the methods in the listener interface. For example: public void actionPerformed(ActionEvent e) { ...//code that reacts to the action... }
Powered by: BlogJava Copyright © tanzek