Example usage for java.applet Applet init

List of usage examples for java.applet Applet init

Introduction

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

Prototype

public void init() 

Source Link

Document

Called by the browser or applet viewer to inform this applet that it has been loaded into the system.

Usage

From source file:ShapeMover.java

public static void main(String s[]) {
    Frame f = new Frame("ShapeMover");
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);/*from   w  ww .ja v  a2  s. c o m*/
        }
    });
    Applet applet = new ShapeMover();
    f.add("Center", applet);
    applet.init();
    f.pack();
    f.setSize(new Dimension(550, 250));
    f.show();
}

From source file:MainClass.java

public static void main(String args[]) {
    String name = "http://urlWithClassName";
    try {//from   ww  w  . ja  v a  2 s.  c om
        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  w w  .j  a v  a2  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);/*  w w w.ja va2s.c om*/
    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();
}