Java ʼþ´¥·¢½Ó¿Ú»Øµ÷·½·¨
Æä¼¼ÇɾÍÊÇ£º¶¨ÒåÒ»¸ö¼òµ¥½Ó¿Ú£¬²¢ÔڸýӿÚÖÐÉùÃ÷ÎÒÃÇÒªµ÷Óõķ½·¨£¬Ò»°ã¿ÉÒÔÓ¦ÓÃÔÚ¼üÅÌÊó±êʼþ¸ú×Ù¡£
ÏÂÃæ¾ÙÒ»¸öÀý×Ó£º
¼Ù¶¨ÎÒÃÇÏ£ÍûÔÚij¸öʼþ·¢ÉúʱµÃµ½Í¨Öª¡£ÎÒÃÇ¿ÉÒÔ¶¨ÒåÒ»¸ö½Ó¿Ú£º
/*
* ÔÚij¸öʼþ·¢ÉúʱµÃµ½Í¨Öª£®
*/
public interface InterestingEvent {
¡¡¡¡ public void interestingEvent(); //ÆäËü·½·¨Ìå¼°·½·¨¶¨ÒåÒ²¿É£®
}
´Ë½Ó¿ÚÖеķ½·¨£¬ÊǸöûÓзµ»ØÖµµÄҲûÓÐÈκβÎÊý£¬Èç¹ûÄúÔ¸ÒâÒ²¿ÉÒÔÓзµ»ØÖµ£¬Ò²¿ÉÒÔ´ø²ÎÊý£®Õâ¾ÍÒª¿´¾ßÌåÐèÇó¶ø¶¨£®
ÕâʹµÃÎÒÃÇ¿ÉÒÔ¿ØÖÆʵÏָýӿڵÄÀàµÄÈκζÔÏó¡£Òò´Ë£¬ÎÒÃDz»±Ø¹ØÐÄÈκÎÍⲿÀàÐÍÐÅÏ¢¡£ÓëÔÚ½« C++ ´úÂëÓÃÓÚMotif ʱʹÓô°¿ÚС²¿¼þµÄÊý¾ÝÓòÀ´ÈÝÄɶÔÏóÖ¸ÕëµÄÄÑÒÔ¿ØÖÆµÄ C º¯ÊýÏà±È£¬ÕâÖÖ·½·¨ÒªºÃµÃ¶à¡£
ʵÏֽӿڵĴúÂëÈçÏ£º
public class CallMe implements InterestingEvent {
public CallMe() {
¡¡¡¡ }
¡¡¡¡ public void interestingEvent() {
¡¡¡¡ System.out.println("·¢ÉúÁËCallMeʼþ£¬¹þ¹þ");
¡¡¡¡}
}
public class CallYou implements InterestingEvent {
public CallYou() {
¡¡ }
public void interestingEvent() {
System.out.println("·¢ÉúÁËCallYouʼþ£¬¹þ¹þ");
}
}
·¢³öʼþÐźŵÄÀà±ØÐëµÈ´ýʵÏÖÁË InterestingEvent ½Ó¿ÚµÄ¶ÔÏ󣬲¢ÔÚÊʵ±Ê±ºòµ÷Óà interestingEvent() ·½·¨¡£
public class EventNotifier {
private InterestingEvent ie; //½Ó¿Ú¶ÔÏóÒýÓÃ
private boolean somethingHappened ;
public EventNotifier() {
somethingHappened = true ;
}
public void setInterestingEvent(InterestingEvent ie){ //²ÎÊýÒýÓø½Öµ
this.ie = ie ;
}
Ïà¹ØÎĵµ£º
¹ØÓÚZKÕâ¸ö¿ò¼Ü,¹úÄÚʹÓõÄÓû§Ó¦¸Ã±È½ÏÉÙ,¹úÄÚµÄ×ÊÁÏÒ²Ï൱µÄÉÙ,µ«ÊÇÔÚ¹úÍâ,Õâ¸ö¶«Î÷ÒѾºÜ¶àÈËÔÚʹÓÃÁË,ÒÔǰҲûÔõô½Ó´¥¹ý,×î½ü¿ªÊ¼Ê¹ÓÃZKÀ´×ö¿ª·¢,·¢ÏÖÕⶫÎ÷ÔÚʹÓõÄʱºò,»¹ÂùÓÐÒâ˼µÄ,ËùÒÔ×¼±¸¼ÇÏÂʹÓÃÈÕÖ¾,Áô¸øÒÔºó»Ø¹ËºÍ´ó¼Ò·ÖÏí
Ê×ÏÈÐèÒªÖªµÀZKÊÇÒ»¸öʲô¶«Î÷,Õâ¸ö¿ò¼ÜÊÇÎÒ¹ų́ÍåµÄÅóÓÑ¿ª·¢µÄ,ËûÊÇÒ»¸öʼþÇý¶¯(e ......
1.·½·¨ÖØÔØ£ºÊÇÖ¸ÔÚÒ»¸öÀàÖÐÓжà¸ö·½·¨µÄÃû×ÖÏàͬ£¬µ«ÕâЩ·½·¨µÄ²ÎÊý±ØÐ벻ͬ£¬¼´ÒªÃ´ÊDzÎÊýµÄ¸öÊý²»Í¬£¬ÒªÃ´ÊDzÎÊýµÄÀàÐͲ»Í¬
×¢Ò⣺ÔÚ·½·¨ÖØÔØÖУ¬·½·¨µÄ·µ»ØÀàÐͺͲÎÊýµÄÃû×Ö²»²ÎÓë±È½Ï
2.·½·¨ÖвÎÊýµÄ´«Öµ£ ......
ÔÚjavaÖÐ ¿ÉÒÔ½«Ä³¸ö¶ÔÏó¸³Öµ¸øÁíÒ»¸ö¶ÔÏó Ö»Òª¸ÃÁ½¸ö¶ÔÏóÊÇÊôÓÚͬһ¸öÀ༴¿É ´Ëʱ ÕâÁ½¸ö¶ÔÏóµÄËùÓгÉÔ±½«Ö¸Ïòͬһ¿éÄÚ´æ
eg£º
public class class1
{
&n ......
ÔÚÎÒÃÇд³ÌÐòµÄʱºò,ÓÐʱ»áÒªÇó±£´æһЩÊý¾Ý,±ÈÈçÓû§Ãû»òÕß±ðµÄ,µ«ÊÇÕâÑùÊý¾ÝÓÖ²»ÊDZ£´æÔÚ³ÌÐòͬһĿ¼ÏÂ,ÕâÑù×öÌ«Ã÷ÏÔÁË,Ò²²»Ì«°²È«,ÄÇÔõô°ìÄØ?Õâ¸öʱºò,Èç¹ûÄÜ°ÑÊý¾Ý±£´æµ½×¢²á±íÀïÃæÈ¥,ÄǸöàºÃ,Ò»À´Òþ±Î,¶þÀ´·½±ã,²»ÖÁÓÚÔÚ³ÌÐòĿ¼ÏÂÉú³ÉÒ»´óƬÎļþ.
ÔÚJAVAÀïÃæ,¿ÉÒÔÀûÓÃjava.util.prefs.PreferencesÀ´¶Ô×¢²á±í½øÐ ......