/* * [MultiInstance.java] * * Summary: Demonstrate AppletContext.getApplets bug which fails for more than 11 instances. * * Copyright: (c) 2014-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2001-03-08 initial */ package com.mindprod.example; import javax.swing.JApplet; import javax.swing.JButton; import java.applet.Applet; import java.applet.AppletContext; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Enumeration; import static java.lang.System.*; // with 12+ instances FireFox, Opera and IE fail. Applets cannot see the other Applets. // Chrome fails with 13+ instances. // With Chrome, ironically fails on 12+ instances. // simple jar build: jar -cvfm multi.jar manifest.mf \com\mindprod\example\MultiInstance*.class // manifest.mf looks like this: // Manifest-Version: 1.0 // Application-Name: MultiInstance // Permissions: sandbox // Created-By: 1.8.0 (Oracle Corporation) // Main-Class: com.mindprod.example.MultiInstance // run with multi.html //that looks like this: // // // // // // //

Click each applet to see which others it can see, listed on the console.

// // // // // // Applet failed to run. // // // // // // // Applet failed to run. // // ... 11 instances will work, 12 will fail. // // /** * Demonstrate AppletContext.getApplets bug which fails for more than 11 instances. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2014-04-12 initial version * @since 2014-04-12 */ public final class MultiInstance extends JApplet { /** * which instance on the page are we, unique string */ private String instance = "unknown"; /** * constructor */ public MultiInstance() { } /** * which instance on the page are * * @return unique instance string */ String getInstance() { return instance; } /** * dump out who can see what */ public void dump() { // dump out what getApplets provides final AppletContext ac = this.getAppletContext(); // all Applets on page, possibly including us, including non-MultiInstance final Enumeration otherApplets = ac.getApplets(); if ( otherApplets == null || !otherApplets.hasMoreElements() ) { out.println( "instance " + instance + " unable to see any other applets" ); } else { while ( otherApplets.hasMoreElements() ) { Applet other = otherApplets.nextElement(); if ( other instanceof MultiInstance ) { out.println( instance + " can see: instance " + ( ( MultiInstance ) other ).getInstance() ); } else { out.println( instance + " can see: " + other.getAppletInfo() ); } } } } public void init() { instance = getParameter( "instance" ); JButton t = new JButton( instance ); t.setBackground( Color.orange ); this.add( t ); t.addActionListener( new ActionListener() { /** * Invoked when user clicks button */ public void actionPerformed( ActionEvent e ) { dump(); } } ); this.validate(); this.setVisible( true ); } // end init // has no main method. }