Class AppletViewer

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants, StatusDisplay

public class AppletViewer extends JFrame implements StatusDisplay
Understands a window that displays an Applet.

Typical usage:

 AppletViewer viewer = AppletViewer.newViewer(new MyApplet());

 // test the applet, viewer can be wrapped with a FrameFixture.
 FrameFixture viewerFixture = new FrameFixture(viewer);

 viewer.unloadApplet() // stops and destroys the applet
 viewerFixture.cleanUp();
 

Note: In version 1.2, due to bug FEST-219 constructors in this class have been replaced with the static factory methods newViewer. It was not possible to just deprecate them. To ensure correct behavior of the applet viewer, they had to be made unaccessible to client code.

See Also:
  • Field Details

  • Constructor Details

    • AppletViewer

      private AppletViewer(Applet applet)
  • Method Details

    • newViewer

      @RunsInEDT public static AppletViewer newViewer(Applet applet)
      Creates a new AppletViewer. This factory method creates new instances of BasicAppletStub and BasicAppletContext.

      Note: This method is executed in the event dispatch thread (EDT.)

      Parameters:
      applet - the applet to view.
      Returns:
      the created AppletViewer.
      Throws:
      NullPointerException - if applet is null.
      Since:
      1.2
    • newViewer

      @RunsInEDT public static AppletViewer newViewer(Applet applet, Map<String,String> parameters)
      Creates a new AppletViewer. This factory method creates new instances of BasicAppletStub and BasicAppletContext.

      Note: This method is executed in the event dispatch thread (EDT.)

      Parameters:
      applet - the applet to view.
      parameters - the parameters included in an applet HTML tag.
      Returns:
      the created AppletViewer.
      Throws:
      NullPointerException - if applet is null.
      NullPointerException - if parameters is null.
      Since:
      1.2
    • newViewer

      @RunsInEDT public static AppletViewer newViewer(Applet applet, AppletStub stub)
      Creates a new AppletViewer.

      Note: This method is executed in the event dispatch thread (EDT.)

      Parameters:
      applet - the applet to view.
      stub - the applet's stub.
      Returns:
      the created AppletViewer.
      Throws:
      NullPointerException - if applet is null.
      NullPointerException - if stub is null.
      Since:
      1.2
    • createInEDT

      @RunsInEDT private static AppletViewer createInEDT(Applet applet)
    • setUpFrame

      private void setUpFrame()
    • addContent

      private void addContent()
    • appletStub

      private void appletStub(AppletStub newAppletStub)
    • setUpApplet

      private void setUpApplet()
    • reloadApplet

      public void reloadApplet()
      Initializes and starts the applet in this viewer.
    • loadApplet

      private void loadApplet()
    • unloadApplet

      public void unloadApplet()
      Stops and destroys the applet loaded in this viewer. This method should be called before closing or disposing this viewer.
    • appletLoaded

      public boolean appletLoaded()
      Indicates whether the applet in this viewer is loaded or not.
      Returns:
      true if this applet is loaded, false otherwise.
    • showStatus

      @RunsInEDT public void showStatus(String status)
      Displays the given status message. This method is executed in the event dispatch thread (EDT.)
      Specified by:
      showStatus in interface StatusDisplay
      Parameters:
      status - the status to display.
    • setStatus

      @RunsInCurrentThread private void setStatus(String status)
    • applet

      public Applet applet()
      Returns the applet displayed in this viewer.
      Returns:
      the applet displayed in this viewer.
    • stub

      public AppletStub stub()
      Returns the AppletStub in this viewer.
      Returns:
      the AppletStub in this viewer.