Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4391593

AppletContext.getApplets doesnt return all applets in browser

XMLWordPrintable

    • beta
    • x86
    • windows_nt, windows_2000



      Name: yyT116575 Date: 11/21/2000


      java version "1.3.0_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0_01)
      Java HotSpot(TM) Client VM (build 1.3.0_01, mixed mode)

      Applet.getApplets() only returns the applet from where the call was made from
      and not all the applets in the other browser frames or even other browser
      windows, as was the case in the 1.3.0 release.

      Please find enclosed java source code and the appropriate HTML to display an
      applet in two frames in an IE browser. Once started press the button to see
      which applets can be located. Using this 1.3.0_01 plugin in IE (or netscape 6)
      only the applet which the user selected the button is returned by the
      getApplets call.

      /******START JAVA CODE******/
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;
      import java.applet.AppletContext;


      /**
       * Title:
       * Description:
       * Copyright: Copyright (c) 2000
       * Company:
       * @author
       * @version 1.0
       */

       import java.util.Enumeration;


      public class MyTestApplet extends JApplet {
        JButton jButton1 = new JButton();
        JTextArea jTextArea1 = new JTextArea();

        public MyTestApplet() {
          try {
            jbInit();
          }
          catch(Exception e) {
            e.printStackTrace();
          }
        }
        private void jbInit() throws Exception {
          jButton1.setText("Press Me!");
          jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
              jButton1_actionPerformed(e);
            }
          });
          jTextArea1.setText("Applet Context Information:\n\n");
          this.getContentPane().add(jButton1, BorderLayout.NORTH);
          this.getContentPane().add(jTextArea1, BorderLayout.CENTER);
        }

        void jButton1_actionPerformed(ActionEvent e) {
          //Button Presed action
          AppletContext context = this.getAppletContext();

          jTextArea1.append("Found the following applets:\n");
          int count = 0;
          for (Enumeration enum = context.getApplets(); enum.hasMoreElements();) {
            count ++;
            JApplet myApplet = (JApplet)enum.nextElement();

            jTextArea1.append(myApplet.toString()+"\n");
          }

          jTextArea1.append("\n\nTherefore " + count+ " applet(s) were found");
        }
      }
      /*END JAVA CODE*/

      /*Start HTML frameset*/
      <HTML>
      <HEAD>
      <TITLE>Jasons Test Applet Context HTML File</TITLE>
      </HEAD>

       <frameset frameborder="yes" cols="235,*">
        <frame name="frame1" src="frame1.html">
        <frame name="frame2" src="frame2.html">
       </frameset>

      </HTML>

      /*End Frameset*/

      /*start frame1.html file*/
      <html>
       <body style="border:0; margin:0; padding:0;">
            <object
                classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
                width="100%"
                height="100%"
                hspace="0"
                vspace="0"
                align="baseline"
            >
                <param name="code" value="MyTestApplet.class" />
                <param name="type" value="application/x-java-applet;version=1.3" />

                No support for Java 2 applets
            </object>
           </body>
      </html>
      /*End frame1.html*/

      /*start frame2.html*/
      <html>
       <body style="border:0; margin:0; padding:0;">
            <object
                classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
                width="100%"
                height="100%"
                hspace="0"
                vspace="0"
                align="baseline"
            >
                <param name="code" value="MyTestApplet" />
                <param name="type" value="application/x-java-applet;version=1.3" />

                No support for Java 2 applets
            </object>
           </body>
      </html>
      /*end frame2.html*/
      (Review ID: 112532)
      ======================================================================

      Name: yyT116575 Date: 12/12/2000


      java version "1.3.0_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0_01)
      Java HotSpot(TM) Client VM (build 1.3.0_01, mixed mode)


      In the 1.3.0_01 Plug-in, getAppletContext().getApplets() only returns one applet
      on the page, not necessarily the applet that is making the call.

      For an html page with two applets:
        In IE, only the second applet in the html source is reported
        In Netscape, only the first applet is reported

      This may be the same bug as 4391593. The example given with that bug report only
      has one applet in each html file.

      Sample code (the html was converted with the 1.3.0_01 HTMLConverter):

      ///////////// JAVA ///////////////

      // Test1.java
      import javax.swing.*;
      import java.util.*;

      public class Test1 extends JApplet {

        public void init() {
          System.out.println("Test1 init()");
        }
        public void start() {
          System.out.println("Test1 other applets: ");
          Enumeration enum = getAppletContext().getApplets();
          if (!enum.hasMoreElements())
              System.out.println("no applets");
          while (enum.hasMoreElements())
              System.out.println(" " + enum.nextElement());
        }
      }

      // Test2.java
      import javax.swing.*;
      import java.util.*;

      public class Test2 extends JApplet {

        public void init() {
          System.out.println("Test2 init()");
        }
        public void start() {
          System.out.println("Test2 other applets: ");
          Enumeration enum = getAppletContext().getApplets();
          if (!enum.hasMoreElements())
              System.out.println("no applets");
          while (enum.hasMoreElements())
              System.out.println(" " + enum.nextElement());
        }
      }


      //////////// HTML ///////////////////


      <html>
      <head><title>Test</title></head>
      <body>
      <applet code=Test1.class width=100 height=100></applet>
      <applet code=Test2.class width=100 height=100></applet>
      </body>
      </html>



      <html>
      <head><title>Test</title></head>
      <body>
      <applet code=Test2.class width=100 height=100></applet>
      <applet code=Test1.class width=100 height=100></applet>
      </body>
      </html>
      (Review ID: 113616)
      ======================================================================

      SAP seems to have the same problem in Internet Explorer.
      Please have a look for the fairly trivial test case in the attachment (testCase.tar). It shows that 2 Applets in one html page can't reference to each other.

      The problem seems to still occur ind SDK 1.3.1_03 and 1.4

            stanleyh Stanley Ho (Inactive)
            yyoungsunw Yung-ching Young (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: