Using/Implementing Appletstub Interface

java packages » java.applet

AppletStub serves as the interface between the applet and the browser environment or applet viewer environment in which the application is running. AppletStub is an easy way to make your applets run as standalone application without any redesign.

Java Example Program / Sample Source Code
import java.applet.Applet;
import java.applet.AppletContext;
import java.applet.AppletStub;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Hashtable;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;

public class AppletStubInterface implements AppletStub {
private Hashtable<String, String> hashtable;
private Applet applet;

public AppletStubInterface(String args[], Applet a) {
applet = a;
hashtable =
new Hashtable<String, String>();
for (int i = 0; i < args.length; i++) {
try {
StringTokenizer parser = new StringTokenizer(args[i], "=");
String name = parser.nextToken
().toString();
String value = parser.nextToken
("\"").toString();
value = value.substring
(1);
hashtable.put
(name, value);
} catch (NoSuchElementException e) {
e.printStackTrace();
}
}
}

public void appletResize(int width, int height) {
applet.resize(width, height);
}

public AppletContext getAppletContext() {
return null;
}

public java.net.URL getCodeBase() {
String host;
if ((host = getParameter("host")) == null) {
try {
host = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
java.net.URL url = null;
try {
url = new java.net.URL("file://" + host);
} catch (Exception e) {
}
return url;
}

public java.net.URL getDocumentBase() {
return getCodeBase();
}

public String getParameter(String param) {
return (String) hashtable.get(param);
}

public boolean isActive() {
return true;
}
}
Html Code
<html>
    <head>
        <title>AppletStubInterface</title>
    </head>
    <body>
        <applet code="AppletStubInterface" width="700" height="500"></applet>
    </body>
</html>

Applet


AppletContext

2011-2021 JavaExamples.org Privacy Policy Powered by Google App Engine