[4272] in java-interest
Applet to put Applet in a Frame...
daemon@ATHENA.MIT.EDU (Pat Niemeyer)
Fri Dec 15 08:22:32 1995
Date: Fri, 15 Dec 1995 06:08:00 -0600 (CST)
From: Pat Niemeyer <pat@icon-stl.net>
To: java-interest@java.sun.com
Here's an applet that will run a specified applet in an external frame.
Put this (or a link to it) at the same base url as your applet.
Change your <applet> tag to specify FrameApplet rather than the one you
want to display. Then add one extra <param> named "applet" with a value
of the name of the applet to run.
It should display the named applet in an external fram and change itself
into a "kill blah" button. Of course, Netscape doesn't support sizing
properly yet. However, the things I've tried work under b3.
Comments? (am I doing anything bogus in here?)
Obvious improvements:
Find a way around the location problem
Add separate width & height to avoid a resize.
/* ---------------------------------------------------------------------- */
import java.awt.*;
import java.applet.*;
import java.net.URL;
/*
FrameApplet
by Pat Niemeyer (pat@pat.net)
*/
public class FrameApplet extends Applet implements AppletStub {
static int PAD = 25;
Frame frame;
Applet applet;
public void init() {
String nam = getParameter("applet");
try {
applet = (Applet)Class.forName( nam ).newInstance();
} catch (Exception e) {
return;
}
frame = new Frame( nam );
frame.setLayout( new BorderLayout() );
applet.setStub( this );
// Netscape lameness
//applet.resize( size() );
applet.resize( size().width, size().height );
applet.init();
frame.add("Center", applet);
frame.show();
applet.start();
setLayout( new BorderLayout() );
add ( "Center", new Button("Kill " + nam) );
// Netscape lameness
//resize( preferredSize() );
resize( preferredSize().width, preferredSize().height );
}
public boolean isActive() {
return super.isActive(); }
public URL getDocumentBase() {
return super.getDocumentBase(); }
public URL getCodeBase() {
return super.getCodeBase(); }
public String getParameter(String name) {
return super.getParameter(name); }
public AppletContext getAppletContext() {
return super.getAppletContext(); }
public void appletResize(int width, int height) {
frame.resize( width+PAD, height+PAD );
}
public boolean action( Event e, Object arg ) {
if ( applet == null )
return true;
applet.stop();
applet.destroy();
frame.dispose();
return true;
}
}
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com