FileDocCategorySizeDatePackage
SecondAppletViewer.javaAPI DocExample2023Tue Jan 25 10:45:14 GMT 2000None

SecondAppletViewer

public class SecondAppletViewer extends HttpServlet

Fields Summary
static final int
WIDTH
static final int
HEIGHT
static final String
APPLETNAME
Constructors Summary
Methods Summary
public voiddoGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)


       
                                  
    ServletOutputStream out = res.getOutputStream();

    MainFrameModified frame = null;
    Graphics g = null;
    Applet applet = null;

    try {
      // Load the SecondApplet
      // Must be in the standard CLASSPATH
      try {
        applet = (Applet) Class.forName(APPLETNAME).newInstance();
      }
      catch (Exception e) { 
        throw new ServletException("Could not load applet:" + e);
      }
  
      // Prepare the applet arguments
      String args[] = new String[1];
      args[0] = "barebones=true";  // run without a menu bar

      // Put the applet in its frame
      // addNotify() is called by MainFrameModified
      frame = new MainFrameModified(applet, args, WIDTH, HEIGHT);
  
      // Get a graphics region to match the applet size, using the Frame
      Image image = frame.createImage(WIDTH, HEIGHT);
      g = image.getGraphics();

      // Ask the applet to paint itself
      applet.validate();
      applet.paint(g);
  
      // Encode and return what it painted
      res.setContentType("image/gif");
      GifEncoder encoder = new GifEncoder(image, out);
      encoder.encode();
    }
    finally {
      // Clean up resources
      if (applet != null) {
        applet.stop();
        applet.destroy();
        applet.removeAll();
      }
      if (g != null) {
        g.dispose();
      }
      if (frame != null) {
        frame.removeAll();
        frame.removeNotify();
        frame.dispose();
      }
    }