Example usage for java.applet Applet start

List of usage examples for java.applet Applet start

Introduction

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

Prototype

public void start() 

Source Link

Document

Called by the browser or applet viewer to inform this applet that it should start its execution.

Usage

From source file:MainClass.java

public static void main(String args[]) {
    String name = "http://urlWithClassName";
    try {//from  w ww  .j  a v  a2  s.  c  o m
        if (!name.endsWith(".class")) {
            System.err.println("That doesn't look like a byte code file!");
            return;
        }
        URL u = new URL(name);
        URLClassLoader ucl = new URLClassLoader(u);

        // parse out the name of the class from the URL
        String s = u.getFile();
        String classname = s.substring(s.lastIndexOf('/'), s.lastIndexOf(".class"));
        Class AppletClass = ucl.loadClass(classname, true);
        Applet apl = (Applet) AppletClass.newInstance();
        JFrame f = new JFrame();
        f.setSize(200, 200);
        f.add("Center", apl);
        apl.init();
        apl.start();
        f.setVisible(true);
    } catch (Exception e) {
        System.err.println(e);
    }
}

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);//from  w ww  . j ava 2 s  .c  o  m

    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);//from  ww w .  j  a va2s  .c  o  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();
}