package sharing; import java.applet.Applet; import java.util.ArrayList; import java.util.List; /** * A utility class of which at most one instance can exist per VM. * Use Singleton.instance() to access this instance. * * Based on http://wiki.java.net/bin/view/Javapedia/Singleton */ public class Singleton { /** * The constructor is be made private to prevent others from * instantiating this class. */ private Singleton() {} /** * A handle to the unique Singleton instance. */ static private Singleton _instance = null; /** * The list of "client" Applets. */ private List clients = new ArrayList(); /** * @return The unique instance of this class. */ static public Singleton instance() { if (null == _instance) { _instance = new Singleton(); } return _instance; } /** * Register the specified Applet as a client. */ public void register(Applet client) { clients.add(client); } /** * @return The list of registered clients. */ public List getClients() { return clients; } }