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
 

"Java - The Software Design"
Volume: 4 Issue: 1, p. 58

	

Listing 1:

public interface RadioBroadcaster {Radio-Broadcast broadcast = new RadioBroad-cast(); 

public voidaddRadioBroadcastListeners-(RadioBroadcastEventListener bel);

public boolean removeRadioBroadcast-Listeners(RadioBroadcastEventListener bel);

public void notifyRadioBroadcastListeners-(RadioBroadcastEvent be);}

public interface RadioBroadcastEvent-Listener extends java.util.EventListener

{public void broadcastPerformed(Radio-BroadcastEvent event);}


Listing 2:

class A implements RadioBroadcaster {.... [any other codes here] ...

//=== defines the method to broadcast events public void
 notifyRadioBroadcast-Listeners(RadioBroadcastEvent be)

{broadcast.notifyRadioBroadcastListeners-(be);}

public void addRadioBroadcastListeners-(RadioBroadcastEventListener bl)

{broadcast.addRadioBroadcastListeners-
(bl); }

public boolean removeRadioBroadcast-Listeners(RadioBroadcastEventListener bl)

{return broadcast.removeRadioBroadcast-Listeners(bl); }

//=== ‘radio broadcast’ an event Radio-BroadcastEvent evt = new
 RadioBroadcast-Event("packagename.A.EventName");

notifyRadioBroadcastListeners(evt);

.... [any other codes here] ... }


Listing 3:

class B implements RadioBroadcast-EventListener { ...[any other codes]...

//=== ‘tune in’ to a certain channel (events transmitted) 
public void broadcast-Performed(RadioBroadcastEvent be) 
{ if (be.getEventID().equals("packagename.A.EventName")) 
{ ...[do something here as required by application logic]... } 
else if (be.getEventID().equals("anyPackageName.anyClassName.anyEventName")) 
{ ...[do something here as required by application logic]... } : 
: ...[any other if else statements]... } 
public void addRadioBroadcastListeners-(RadioBroadcastEventListener bl) 
{ broadcast.addRadioBroadcastListeners(bl); }

public boolean removeRadioBroadcast-Listeners(RadioBroadcastEventListener bl)
 { return broadcast.removeRadioBroadcast-Listeners(bl); }

//=== register itself (class B) as one of the radio listeners

ServiceBroker.getClassA().addRadioBroadcastListeners(this);

...[any other codes]...

//=== remove itself (class B) from listening if there is a need to do so
 ServiceBroker.getClassA().removeRadioBroadcastListeners(this);

...[any other codes]... }


Listing 4:

class RadioBroadcast { Vector listeners = new Vector();

public void notifyRadioBroadcastListeners-(RadioBroadcastEvent be) 
{ Enumeration notifyList = listeners.elements();

while (notifyList.hasMoreElements()) {
 ((RadioBroadcastEventListener)notifyList.nextElement()).broadcastPerformed(be); } }

public void addRadioBroadcastListeners-(RadioBroadcastEventListener bl) { listeners.addElement(bl); }

public boolean removeRadioBroadcast-Listeners(RadioBroadcastEventListener bl) { return
 (listeners.removeElement(bl)); } }

public class RadioBroadcastEvent extends java.util.EventObject implements
 java.io.Serializable { private String eventID;

public RadioBroadcastEvent(String eventID) {super(eventID); this.eventID = eventID;}

public String getEventID() { return eventID;} }


Listing 5:

public class ServiceBroker { private static JLayeredPane layeredPane = null;
private static SMediaPlayer mediaPlayer = null;

private static UserProfile uProfile = null;

private static A classA = null;

public final static int AUDIO_MANUAL = 0;

public final static int AUDIO_AUTO = 1;

public final static int VIDEO_MANUAL = 0;

public final static int VIDEO_AUTO = 1;

...[any other declaration codes]...

/** Returns the user profile of the user who has successfully logged in */ public static
 UserProfile getUserProfile() { return uProfile; }

/** Sets the current user profile to the user profile of the user id who has successfully logged in, 
@param CurrentUserId: 
the User id whose user profile is to be used to set the property 
*/ public static void setUser-Profile(String CurrentUserId)
{ user_list = (UserList)Broker.loadObject(sUtil.getUserDir()+SignOn.USERLIST_PATH);

uProfile = user_list.getUser(CurrentUserId);

currentUser = uProfile.getUserID();

uProfile.setUserSessionFileName(currentUser+"001"); }

public static JLayeredPane getLayered-Pane() { return layeredPane; }

/** Returns object of class A */ public static A getClassA(){ if(classA == null){ classA = new A();

classA.init(); }

return classA; }

...[any other codes]... }


      
 

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.