The first time I heard that monitoring was three years ago, to do a Webgis project, at that time, the impression of listener is a "monitor", monitoring the interface of every move, a response to trigger the corresponding.
By adding a listener to one or more of the interfaces, the Listener function/listener class can be invoked spontaneously to respond to the operation. A chestnut: the operation being monitored is "you made your mother angry", adding the response is "Your mom called your dad, your dad went home, your dad beat you up." So whenever you get angry with your mom, it triggers the listener, and the end result is that you'll be beaten by your dad every time. Tried, without exception. This is the event monitoring, Java.util.EventListener.
Listener a lot of kinds, but I can't sum up a macro-framework, here only the commonly used CS monitoring listed to say, not enough to be added later: Actionlistener,mouselistener,popmenulistener and so on.
1. Add a listener directly to the control, such as adding a ActionListener listener to the Save button
1 Savecharaeditbutton.addactionlistener (new ActionListener () {2 3 @Override4public void actionperformed (ActionEvent e) {5 // TODO auto-generated method stub6 Save (); 7 }8 });
2. Write a listener class and inherit the listener interface. Add event listener only need to implement this listener class is OK
1 PublicJPanel Setrightpanel () {2JPanel Rightpanel =NewJPanel ();3 Double[] size = {{15,tablelayout.fill,30,tablelayout.fill,35},{10,30,10, Tablelayout.fill}};4Rightpanel.setlayout (Newtablelayout (size));5JButton Savecharaeditbutton =NewJButton ("Save Edit");6JButton Enablecharaeditbutton =NewJButton ("Enable editing");7Rightpanel.add (Enablecharaeditbutton, "the");8Rightpanel.add (Savecharaeditbutton, "3,1");9Rightpanel.add (Setcharajctablepanel (), "0,3,4,3");TenSavecharaeditbutton.addactionlistener (NewSaveedittofloodcharactervaluelistener ());//Add Listener One returnRightpanel; A}
1 classSaveedittofloodcharactervaluelistenerImplementsactionlistener{2 3 @Override4 Public voidactionperformed (ActionEvent e) {5 //TODO auto-generated Method Stub6Floodcharactervalue Floodcharactervalue =NewFloodcharactervalue (); 7Floodcharactervalue =Floodcharactervalue.transfldproptofloodcharactervalue (editcharafldprop);8M_doc.m_floodextractcharactervalue =Floodcharactervalue;9 }10}
Java Development Summary: Use of more comfortable event monitoring