ptapplet._java


    // Applets
    
    Hashtable	applets = null; // Keys are property strings
    Vector  app_properties = null;  // The applets properties lists
    

	void app_init(){
		applets = new Hashtable();
		app_properties = new Vector();
	}
		
		

	/** Start Applet from list of applets
    * @param n The list number
	*/
	public void startApplet(int n ){
		if( n<0 || app_properties == null || n >= app_properties.size() 
				|| app_properties.elementAt(n) == null ) return;
		
		if( applets.get( app_properties.elementAt(n) ) !=null )
			stopApplet( n );


		try{
			String cname = myGetParameter( (String)app_properties.elementAt(n), "code" );
			Class c = Class.forName( cname.substring( 0, cname.lastIndexOf(".class") ));
	    	Constructor ac = c.getConstructor( new Class[]{ Class.forName("ptviewer"), String.class });
	    	Applet a = (Applet) ac.newInstance( new Object[]{ this, app_properties.elementAt(n) });
	    	applets.put(app_properties.elementAt(n), a);
	    	a.init();
	    	a.start();
		}catch(Exception e){
			// Try another constructor (without arguments);
			try{
				String cname = myGetParameter( (String)app_properties.elementAt(n), "code" );
				Class c = Class.forName( cname.substring( 0, cname.lastIndexOf(".class") ));
	    		Constructor ac = c.getConstructor(new Class[]{});
	    		Applet a = (Applet) ac.newInstance(new Object[]{});
	    		applets.put(app_properties.elementAt(n), a);
				
				Class p = Class.forName( "ptstub" );
	    		Constructor pc = p.getConstructor(new Class[]{ Class.forName("ptviewer"), String.class });
	    		AppletStub as = (AppletStub) pc.newInstance(new Object[]{ this, app_properties.elementAt(n) });
	    		a.setStub( as );
	    		a.init();
	    		a.start();
			}catch(Exception e1){}
		}
		
		return;
	}			
	
	/** Stop Applet from list of applets
    * @param n The list number
	*/
	public void stopApplet(int n ){
		if( n<0 || app_properties == null || n >= app_properties.size() 
				|| app_properties.elementAt(n) == null ) return;
		
		Applet a = (Applet)applets.get( app_properties.elementAt(n) );
		
		if(a!=null){
			a.stop();
			//a.destroy();
			applets.remove( app_properties.elementAt(n) );
		}	
	}
	

	void stopApplets(int k){
		for(int i=k; i<app_properties.size(); i++){
			stopApplet( i );
		}	
    }
	
	

Back