Example usage for java.applet Applet setStub

List of usage examples for java.applet Applet setStub

Introduction

In this page you can find the example usage for java.applet Applet setStub.

Prototype

public final void setStub(AppletStub stub) 

Source Link

Document

Sets this applet's stub.

Usage

From source file:MinAppletviewer.java

public static void main(String args[]) throws Exception {
    AppSupport theAppSupport = new AppSupport();
    JFrame f = new JFrame();
    URL toload = new URL(args[0]);
    String host = toload.getHost();
    int port = toload.getPort();
    String protocol = toload.getProtocol();
    String path = toload.getFile();
    int join = path.lastIndexOf('/');
    String file = path.substring(join + 1);
    path = path.substring(0, join + 1);/*w  ww .  j a v a 2  s. c  om*/

    theAppSupport.setCodeBase(new URL(protocol, host, port, path));
    theAppSupport.setDocumentBase(theAppSupport.getCodeBase());

    URL[] bases = { theAppSupport.getCodeBase() };
    URLClassLoader loader = new URLClassLoader(bases);
    Class theAppletClass = loader.loadClass(file);
    Applet theApplet = (Applet) (theAppletClass.newInstance());

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    f.add(theApplet, BorderLayout.CENTER);

    theApplet.setStub(theAppSupport);

    f.setSize(200, 200);
    f.setVisible(true);
    theApplet.init();
    theApplet.start();
}

From source file:DummyAppletContext.java

private void init(Applet applet, int default_width, int default_height, String args[], int startidx) {

    URL.setURLStreamHandlerFactory(this);

    applets.addElement(applet);// ww  w. ja  v  a 2  s  . co m
    applet.setStub(this);

    initial_width = default_width;
    initial_height = default_height;

    parseArgs(args, startidx);

    status = new TextField();
    status.setEditable(false);

    add("Center", applet);
    add("South", status);

    appletResize(initial_width, initial_height);

    show();
    applet.init();
    applet.start();
}