繼續(xù)在看Java Tutorial,不過(guò)已經(jīng)到了GUI了,呵呵!~在"Introduction to Event Listeners"中,看到了JAVA的事件監(jiān)聽機(jī)制。實(shí)現(xiàn)事件監(jiān)聽機(jī)制,需要有如下三件事情:
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