MainFrameModifiedpublic class MainFrameModified extends Frame implements AppletStub, Runnable, AppletContext
Fields Summary |
---|
private String[] | args | private static int | instances | private String | name | private boolean | barebones | private Applet | applet | private Label | label | private Dimension | appletSize | private String | PARAM_PROP_PREFIX |
Constructors Summary |
---|
public MainFrameModified(Applet applet, String[] args, int width, int height)
/// Constructor with everything specified.
build( applet, args, width, height );
| public MainFrameModified(Applet applet, String[] args)
build( applet, args, -1, -1 );
| public MainFrameModified(Applet applet, int width, int height)
build( applet, null, width, height );
|
Methods Summary |
---|
public void | appletResize(int width, int height)
// Change the frame's size by the same amount that the applet's
// size is changing.
Dimension frameSize = size();
frameSize.width += width - appletSize.width;
frameSize.height += height - appletSize.height;
resize( frameSize );
appletSize = applet.size();
| private void | build(java.applet.Applet applet, java.lang.String[] args, int width, int height)
++instances;
this.applet = applet;
this.args = args;
applet.setStub( this );
name = applet.getClass().getName();
setTitle( name );
// Choose a unique parameter property prefix.
PARAM_PROP_PREFIX = "parameter." + hashCode() + ".";
// Set up properties.
Properties props = System.getProperties();
props.put( "browser", "Acme.MainFrame" );
props.put( "browser.version", "11jul96" );
props.put( "browser.vendor", "Acme Laboratories" );
props.put( "browser.vendor.url", "http://www.acme.com/" );
// Turn args into parameters by way of the properties list.
if ( args != null )
parseArgs( args, props );
// If width and height are specified in the parameters, override
// the compiled-in values.
String widthStr = getParameter( "width" );
if ( widthStr != null )
width = Integer.parseInt( widthStr );
String heightStr = getParameter( "height" );
if ( heightStr != null )
height = Integer.parseInt( heightStr );
// Were width and height specified somewhere?
if ( width == -1 || height == -1 )
{
System.err.println( "Width and height must be specified." );
return;
}
// Do we want to run bare-bones?
String bonesStr = getParameter( "barebones" );
if ( bonesStr != null && bonesStr.equals( "true" ) )
barebones = true;
if ( ! barebones )
{
// Make menu bar.
MenuBar mb = new MenuBar();
Menu m = new Menu( "Applet" );
m.add( new MenuItem( "Restart" ) );
m.add( new MenuItem( "Clone" ) );
m.add( new MenuItem( "Close" ) );
m.add( new MenuItem( "Quit" ) );
mb.add( m );
setMenuBar( mb );
}
// Lay out components.
setLayout( new BorderLayout() );
add( "Center", applet );
if ( ! barebones )
{
Panel borderPanel =
new Acme.Widgets.BorderPanel( Acme.Widgets.BorderPanel.RAISED );
borderPanel.setLayout( new BorderLayout() );
label = new Label( "" );
borderPanel.add( "Center", label );
add( "South", borderPanel );
}
// Set up size.
pack();
validate();
appletSize = applet.size();
applet.resize( width, height );
//show();
// Start a separate thread to call the applet's init() and start()
// methods, in case they take a long time.
//(new Thread( this )).start();
run();
| public java.applet.Applet | getApplet(java.lang.String name)
// Returns this Applet or nothing.
if ( name.equals( this.name ) )
return applet;
return null;
| public java.applet.AppletContext | getAppletContext()
return this;
| public java.util.Enumeration | getApplets()
// Just yields this applet.
Vector v = new Vector();
v.addElement( applet );
return v.elements();
| public java.applet.AudioClip | getAudioClip(java.net.URL url)
// This is an internal undocumented routine. However, it
// also provides needed functionality not otherwise available.
// I suspect that in a future release, JavaSoft will add an
// audio content handler which encapsulates this, and then
// we can just do a getContent just like for images.
return new sun.applet.AppletAudioClip( url );
| public java.net.URL | getCodeBase()
// Hack: loop through each item in CLASSPATH, checking if
// the appropriately named .class file exists there. But
// this doesn't account for .zip files.
String path = System.getProperty( "java.class.path" );
Enumeration st = new StringTokenizer( path, File.pathSeparator );
while ( st.hasMoreElements() )
{
String dir = (String) st.nextElement();
String transname = name.replace( '.", File.separatorChar );
String filename = dir + File.separatorChar + transname + ".class";
File file = new File( filename );
if ( file.exists() )
{
String urlDir = dir.replace( File.separatorChar, '/" );
try
{
return new URL( "file:" + urlDir + "/" );
}
catch ( MalformedURLException e )
{
return null;
}
}
}
try
{
return new URL("http://localhost/");
}
catch (MalformedURLException e)
{
return null;
}
| public java.net.URL | getDocumentBase()
// Returns the current directory.
String dir = System.getProperty( "user.dir" );
String urlDir = dir.replace( File.separatorChar, '/" );
try
{
return new URL( "file:" + urlDir + "/");
}
catch ( MalformedURLException e )
{
return null;
}
| public java.awt.Image | getImage(java.net.URL url)
Toolkit tk = Toolkit.getDefaultToolkit();
try
{
ImageProducer prod = (ImageProducer) url.getContent();
return tk.createImage( prod );
}
catch ( IOException e )
{
return null;
}
| public java.lang.String | getParameter(java.lang.String name)
// Return a parameter via the munged names in the properties list.
return System.getProperty( PARAM_PROP_PREFIX + name.toLowerCase() );
| public boolean | handleEvent(java.awt.Event evt)
switch ( evt.id )
{
case Event.ACTION_EVENT:
if ( evt.arg.equals( "Restart" ) )
{
applet.stop();
applet.destroy();
Thread thread = new Thread( this );
thread.start();
}
else if ( evt.arg.equals( "Clone" ) )
{
try
{
new MainFrameModified(
(Applet) applet.getClass().newInstance(), args,
appletSize.width, appletSize.height );
}
catch ( IllegalAccessException e )
{
showStatus( e.getMessage() );
}
catch ( InstantiationException e )
{
showStatus( e.getMessage() );
}
}
else if ( evt.arg.equals( "Close" ) )
{
hide();
remove( applet );
applet.stop();
applet.destroy();
if ( label != null )
remove( label );
dispose();
--instances;
if ( instances == 0 )
System.exit( 0 );
}
else if ( evt.arg.equals( "Quit" ) )
System.exit( 0 );
break;
case Event.WINDOW_DESTROY:
System.exit( 0 );
break;
}
return super.handleEvent( evt );
| public boolean | isActive()
return true;
| private void | parseArgs(java.lang.String[] args, java.util.Properties props)
for ( int i = 0; i < args.length; ++i )
{
String arg = args[i];
int ind = arg.indexOf( '=" );
if ( ind == -1 )
props.put( PARAM_PROP_PREFIX + arg.toLowerCase(), "" );
else
props.put(
PARAM_PROP_PREFIX + arg.substring( 0, ind ).toLowerCase(),
arg.substring( ind + 1 ) );
}
| public void | run()
showStatus( name + " initializing..." );
applet.init();
validate();
showStatus( name + " starting..." );
applet.start();
validate();
showStatus( name + " running..." );
| public void | showDocument(java.net.URL url)
// Ignore.
| public void | showDocument(java.net.URL url, java.lang.String target)
// Ignore.
| public void | showStatus(java.lang.String status)
if ( label != null )
label.setText( status );
|
|