HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Adding a Custom Event to a JavaBean"
Volume: 4 Issue: 8, p. 74

	

Listing 1: 

public class LoginEvent extends EventObject { 
   private String sUSERNAME; 
   private boolean bVALIDATED; 
  
   LoginEvent(Object source) { 
      super(source); 
   } 
   LoginEvent(Object source, String sUsr, boolean bValidated) { 
         this(source); 
         sUSERNAME = sUsr; 
         bVALIDATED = bValidated; 
   } 
   public String getUsername() { return sUSERNAME; } 
   public boolean getValidated() { return bVALIDATED; } 
} 

Listing 2: 

public addLoginEventListener( LoginEventListener el ) { 
   vListeners.addElement( el ); 
} 
public removeLoginEventListener ( LoginEventListener el ) { 
   vListeners.removeElement( el ); 
} 

Listing 3: 

private void fireValidatedEvent(String sUsr,boolean bValidated) { 
   Vector v; 
   LoginEvent e; 
   v = (Vector) vListeners.clone(); 
   e = new LoginEvent(this, sUsr, bValidated); 
   for (int i=0; i<v.size(); i++) { 
   LoginEventListener el = (LoginEventListener) 
      v.elementAt(i); 
      el.actionValidated(e); } 
} 

Listing 4: 

public class appNetApps extends Applet implements 
LoginEventListener { 
*** 
*** 
bnLoginBean bnLogin = new bnLoginBean(); 
bnLogin.addLoginEventListener( this ); 
// adds this object to the vListeners Vector in the bean 
*** 
*** 
public void actionValidated(LoginEvent e) { 
// code here for handling event when user clicks <OK> on 
// login bean 
} 
public void actionCanceled(LoginEvent e) { 
// code here for handling event when user clicks <Cancel> on 
// login bean 
} 


 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.