ページ上のすべてのアプレットを一覧表示する方法

ページ上のすべてのアプレットをリストする方法

getAppletContext().getApplets()」メソッドは、ページにロードされたすべてのアプレットを含む「Enumeration」オブジェクトを返します。

この例にはボタンが含まれています。クリックすると、ページ上のすべてのアプレットがリストされ、テキスト領域に1行ずつ表示されます。

package com.example.applet;

import java.applet.Applet;
import java.awt.Button;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Enumeration;

public class AppletExample1 extends Applet implements ActionListener {

    Button button;
    TextArea textBox;

    public void init(){
        button = new Button("List All applets Name");
        button.setActionCommand("CHANGEME");
        button.addActionListener(this);
        add(button);

                textBox = new TextArea(5,40);
            add(textBox);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getActionCommand().equals("CHANGEME")){

            Enumeration applets = getAppletContext().getApplets();

            while (applets.hasMoreElements()) {

                Applet applet = (Applet)applets.nextElement();
                String info = ((Applet)applet).getAppletInfo();
            textBox.append("- " + applet.getClass().getName() + "\n");

            }
        }
    }
}