Mechanism of interface and event

Recommended for you: Get network issues from WhatsUp Gold. Not end users.
As we all know, class inheritance for single inheritance, a class can only have one parent class. However, sometimes in order to realize the multiple inheritance (reusable code), then use interface, i.e. classes can inherit from more than one interface, have more than one parent interface. Interface a series of method statement, is a collection of feature, feature only method without method, so the method can be in different places are different classes, and these can have different behavior (function). While the class inherits the interface must be all methods defined interfaces are implemented, otherwise it will report an error, namely the interface force programmers will all abstract methods are realized.
    In short, the interface will feature only responsible for encapsulating method for class, after class, inherit the interface unless there is characteristic of the interface does not need other common. The interface is equivalent to a toolbox, toolbox function implementation tools still rely on as a user class
    Define an interface for the interface keyword, property is public, the static and final (i.e. not be inheritance cannot be overridden); while the interface can also inherit from more than one interface, the format for the public interface interface extends interface,... {}; interface can define constants, and the constant name all uppercase, format for
Public static final data type constant name = value    
Or static final data type constant name = value    
Or data type constant name = value,
But the methods in the interface is the abstract [abstract] and open [public], the format defines an abstract method
Public abstract the return value data type method name (data type parameter,...);
Or the return value of abstract data type methods (data type parameter,...);
Or return value data type method name (data type parameter,...);
Note, an abstract method does not have a method body {}, that is not the actual code, and can not be constructed, cannot be instantiated object, the equivalent of a be filled shell.
    Now, the definition of a class, to the previously defined interface, realize the given interface method specific, realize the keyword implements
The public class class extends parent class implements interface,... {}
Note that, if the interface to the class inheritance, to inherit the class implementing the interface
The interface is a special class, another special kind of class is introduced, which is between class and abstract class, can all the properties and methods defined in the class, can also be defined in the interface of constants and abstract method, but it cannot be instantiated object like interface, its definition format for public abstract class abstract class {}
  
In making the Swing graphical interface, for example, JButton interface button, click is not achieve any effect, need to add an event to achieve the anticipated function. For example, click the pop-up another window, that, in order to achieve click effect, need to catch on this action, you need to add an event listener, as the name suggests is to monitor whether the Swing component (Swing component acts as an event source) took action, judge need not to need to trigger follow-up code. Event listeners are used
addActionListener(ActionListener l); Action listener method, capture the event source (input) enter and event sources (button) on mouse click
addMouseListener(MouseListener l); Mouse listener method, to capture the event source mouse click, release, click, enter and leave.
addMouseMotionListener(MouseMotionListener l); Mobile mouse listener method captures the event source, press the mouse dragging or moving the mouse.
addKeyListener(KeyListener l); Keyboard monitoring method, whether the button is pressed to capture the event source, release.
These listeners are interface, thus, to define an event handling class to realize all the corresponding listener interfaces, this time is the real gift in Swing assembly operation significance
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Malcolm at December 08, 2013 - 2:42 AM