Packages
 In this topic

*Constructors

*Methods

 

Packages   PreviousThis PackageNext
Package com.ms.ui   Previous This
Package
Next

 


Class UIApplet

public class UIApplet extends UIPanel
{
  // Constructors
  public UIApplet();

  // Methods
  public void destroy();
  public Applet getApplet();
  public AppletContext getAppletContext();
  public String getAppletInfo();
  public AudioClip getAudioClip(URL url);
  public AudioClip getAudioClip(URL url, String name);
  public URL getCodeBase();
  public URL getDocumentBase();
  public Image getImage(URL url);
  public Image getImage(URL url, String name);
  public String getParameter(String name);
  public String[][] getParameterInfo();
  public void init();
  public boolean isActive();
  public void play(URL url);
  public void play(URL url, String name);
  public final void setStub(AppletStub stub);
  public void showStatus(String msg);
  public void start();
  public void stop();
}

This class provides a container for implementing an applet.

Note To run under JDK 1.02, you must be sure to specifically set the layout manager.

The following example shows how this class is used in conjunction with the AwtUIApplet bridge class to create a basic AFC applet.

// MyApplet.java

import com.ms.ui.*;

// Bridge class.
public class MyApplet extends AwtUIApplet
{
  // Constructor.
  public MyApplet () 
  { 
    super (new MyAppletImplementation ()); 
  }
}

// Implementation class.
class MyAppletImplementation extends UIApplet
{
  // Applet entry point
  public void init()
  {
    // Add your components here.
  }
}

If any of the applet's methods are to be scriptable, they must be implemented in this class and exposed to the host through the AwtUIApplet bridge class.

It's often advantageous to create an applet that can be run as a stand-alone application as well as an applet. One way to do this is to create a top-level frame object (based on UIFrame) to host the applet. The following example illustrates this technique and shows how to expose a scriptable method to an applet's host.

// MyApplet.java

import java.awt.*;
import com.ms.ui.*;
import com.ms.fx.*;

// Bridge class.
public class MyApplet extends AwtUIApplet
{
  // Constructor.
  public MyApplet ()
  {
    // Create instance of applet implementation.
    super (new MyAppletImplementation ());
  }
    
  // Stand-alone application entry point.
  public static void main(String args[])
  {
    // Create a frame to contain applet.
    MyAppletFrame f = new MyAppletFrame ("MyApplet Application");
    f.setVisible (true);
    f.setSize (320, 200);

    // Create instance of applet implementation and add to frame.
    MyAppletImplementation applet = new MyAppletImplementation ();
    f.add (applet);

    // Stand-alone application must explicitly call init(). 
    applet.init ();
  }

  // Add pass-through methods for scriptable applet methods here.
  public String getInfo () 
  {
    return (((MyAppletImplementation) getUIApplet ()).getInfo ());
  }
}

// Implementation class.
class MyAppletImplementation extends UIApplet
{
  // Applet entry point.
  public void init()
  {
    setBackground (FxColor.cyan);

    // Add additional components here.
  }

  public String getInfo ()
  {
    String s = "Info about MyApplet.class\r\n";
    s += "Version: 1.0\r\n";
    return s;
  }
}

class MyAppletFrame extends UIFrame
{
  // Constructor.
  public MyAppletFrame(String str)
  {
    super (str);
  }

  public boolean handleEvent (Event e)
  {
    switch (e.id)
    {
    case Event.WINDOW_DESTROY:
      // Frame window closed, exit app
      System.exit (0);
      return true;
    default:
      return super.handleEvent (e);
    }
  }
}
UIComponent
  |
  +--UIContainer
    |
    +--UIStateContainer
      |
      +--UIPanel
        |
        +--UIApplet

Constructors

UIApplet

public UIApplet();

Creates a new UIApplet with a UIBorderLayout manager.

Methods

destroy

public void destroy();

Called by the browser or applet viewer to inform this applet that it is being reclaimed, and that it should destroy any resources it has allocated. The stop method will always be called before destroy.

Note This method should be overwritten if the Applet needs to perform any operations before it is destroyed. For example, an applet with threads would use the init method to create the threads and the destroy method to dispose of them.

The implementation of this method provided by the Applet class does nothing.

(JDK1.0 )

Return Value:

No return value.

See Also: java.applet.Applet.init, java.applet.Applet.start, java.applet.Applet.stop

getApplet

public Applet getApplet();

Retrieves the underlying AWT Applet that is the basis for this applet.

Return Value:

Returns The underlying Applet.

getAppletContext

public AppletContext getAppletContext();

Determines this applet's context, which allows the applet to query and affect the environment in which it runs.

Return Value:

Returns the applet's context.

Remarks:

This environment of an applet represents the document that contains the applet.

(JDK1.0)

Exceptions:

IllegalArgumentException if the Applet was created without a UIApplet host.

getAppletInfo

public String getAppletInfo();

Retrieves information about this applet. An applet should override this method to return a String containing information about the author, version, and copyright of the applet.

Return Value:

Returns a string containing information about the author, version, and copyright of the applet.

Remarks:

The implementation of this method provided by the Applet class returns null.

(JDK1.0)

getAudioClip

public AudioClip getAudioClip(URL url);

Retrieves the AudioClip object specified by the URL argument.

Note This method always returns immediately, whether the audio clip exists. When this applet attempts to play the audio clip, the data will be loaded.

(JDK1.0 )

Return Value:

Returns the audio clip at the specified URL.

ParameterDescription
url An absolute URL, giving the location of the audio clip.

Exceptions:

IllegalArgumentException if the Applet was created without a UIApplet host.

See Also: java.applet.AudioClip

getAudioClip

public AudioClip getAudioClip(URL url, String name);

Retrieves the AudioClip object specified by the URL and name arguments.

Note This method always returns immediately, whether the audio clip exists. When this applet attempts to play the audio clip, the data will be loaded.

(JDK1.0 )

Return Value:

Returns the audio clip at the specified URL.

ParameterDescription
url An absolute URL, giving the base location of the audio clip.
name The location of the audio clip, relative to the url argument.

Exceptions:

IllegalArgumentException if the Applet was created without a UIApplet host.

See Also: java.applet.AudioClip

getCodeBase

public URL getCodeBase();

Retrieves the base's URL. This is the URL of the applet itself.

(JDK1.0 )

Return Value:

Returns the URL of this applet.

Exceptions:

IllegalArgumentException if the Applet was created without a UIApplet host.

See Also: java.applet.Applet.getDocumentBase

getDocumentBase

public URL getDocumentBase();

Retrieves the document's URL. This is the URL of the document in which the applet is embedded.

(JDK1.0 )

Return Value:

Returns the URL of the document that contains this applet.

Exceptions:

IllegalArgumentException if the Applet was created without a UIApplet host.

See Also: java.applet.Applet.getCodeBase

getImage

public Image getImage(URL url);

Retrieves an Image object that can be painted on the screen. The url that is passed as an argument must specify an absolute URL.

Note This method always returns immediately, whether the image exists. When this applet attempts to draw the image on the screen, the data will be loaded. The graphics primitives that draw the image will incrementally paint the image on the screen.

(JDK1.0 )

Return Value:

Returns the image at the specified URL.

ParameterDescription
url An absolute URL, giving the location of the image.

Exceptions:

IllegalArgumentException if the Applet was created without a UIApplet host.

See Also: java.awt.Image

getImage

public Image getImage(URL url, String name);

Retrieves an Image object that can be painted on the screen. The url argument must specify an absolute URL. The name argument is a specifier that is relative to the url argument.

Note This method always returns immediately, whether the image exists. When this applet attempts to draw the image on the screen, the data will be loaded. The graphics primitives that draw the image will incrementally paint the image on the screen.

(JDK1.0 )

Return Value:

Returns the image at the specified URL.

ParameterDescription
url An absolute URL, giving the base location of the image.
name The location of the image, relative to the url argument.

See Also: java.awt.Image

getParameter

public String getParameter(String name);

Retrieves the value of the named parameter in the HTML tag.

Return Value:

Returns the value of the named parameter.

ParameterDescription
name A parameter name.

Remarks:

For example, if this applet is specified as


	<applet code="Clock" width=50 height=50>
	<param name=Color value="blue">
	</applet>

a call to getParameter(»Color») returns the value blue.

The name argument is case insensitive.

(JDK1.0)

Exceptions:

IllegalArgumentException if the Applet was created without a UIApplet host.

getParameterInfo

public String[][] getParameterInfo();

Retrieves information about the parameters that are applicable to this applet. An applet should override this method to return an array of Strings describing these parameters.

Return Value:

Returns an array describing the parameters applicable to this applet.

Remarks:

Each element of the array should be a set of three Strings containing the name, the type, and a description. For example:


String pinfo[][] = {
	 {"fps",    "1-10",    "frames per second"},
	 {"repeat", "boolean", "repeat image loop"},
	 {"imgs",   "url",     "images directory"}
};

The implementation of this method provided by the Applet class returns null.

(JDK1.0)

Exceptions:

IllegalArgumentException if the Applet was created without a UIApplet host.

init

public void init();

Called by the browser or applet viewer to inform this applet that it has been loaded into the system. getCodeBase is called before the first time the start method is called.

Note This method should be overwritten when there is initialization to perform. For example, an applet with threads would use the init method to create the threads and the destroy method to dispose of them.

The implementation of this method provided by the Applet class does nothing.

(JDK1.0 )

Return Value:

No return value.

See Also: java.applet.Applet.destroy, java.applet.Applet.start, java.applet.Applet.stop

isActive

public boolean isActive();

Determines if this applet is active.

Return Value:

Returns True if the applet is active; otherwise, returns false.

Remarks:

An applet is marked active just before its start method is called. It becomes inactive immediately after its stop method is called.

(JDK1.0)

Exceptions:

IllegalArgumentException if the Applet was created without a UIApplet host.

See Also: java.applet.Applet.start, java.applet.Applet.stop

play

public void play(URL url);

Plays the audio clip at the specified absolute URL. The audio clip is not played if it cannot be found.

(JDK1.0 )

Return Value:

No return value.

ParameterDescription
url An absolute URL, giving the location of the audio clip.

Exceptions:

IllegalArgumentException if the Applet was created without a UIApplet host.

play

public void play(URL url, String name);

Plays the audio clip given the URL and a specifier that is relative to it. The audio clip is not played if it cannot be found

(JDK1.0 )

Return Value:

No return value.

ParameterDescription
url An absolute URL, giving the base location of the audio clip.
name The location of the audio clip, relative to the url argument.

Exceptions:

IllegalArgumentException if the Applet was created without a UIApplet host.

setStub

public final void setStub(AppletStub stub);

Sets this applet's stub. This is done automatically by the system.

Return Value:

No return value.

ParameterDescription
stub The new stub.

showStatus

public void showStatus(String msg);

Requests that the argument string be displayed in the status window.

(JDK1.0 )

Return Value:

No return value.

ParameterDescription
msg A string to display in the status window.

Exceptions:

IllegalArgumentException if the Applet was created without a UIApplet host.

start

public void start();

Called by the browser or applet viewer to inform this applet that it should start its execution. It is called after the init method and each time the applet is revisited in a Web page.

Note This method should be overwritten if the applet needs to execute any operations each time the Web page containing it is visited. For example, an applet with animation might want to use the start method to resume animation, and the stop method to suspend the animation.

The implementation of this method provided by the Applet class does nothing.

(JDK1.0 )

Return Value:

No return value.

See Also: java.applet.Applet.destroy, java.applet.Applet.init, java.applet.Applet.stop

stop

public void stop();

Called by the browser or applet viewer to inform this applet to stop its execution. It is called when the Web page that contains this applet has been replaced by another page, and just before the applet is to be destroyed.

Note This method should be overwritten if the Applet needs to perform any operations each time the Web page containing it is no longer visible. For example, an applet with animation might want to use the start method to resume animation, and the stop method to suspend the animation.

The implementation of this method provided by the Applet class does nothing.

(JDK1.0 )

Return Value:

No return value.

See Also: java.applet.Applet.destroy, java.applet.Applet.init

upnrm.gif © 1998 Microsoft Corporation. All rights reserved. Terms of use.