Technical Support
Discussion Forum
Online Training
Read About Java
Java In-Depth
Product Discounts
Membership Information

Java Cup Logo

JDC Home Page


Working Applet
Help and Hints
Source Code
Table of Contents
Online Training
shadowSearchFAQFeedback

Solution

Download ListTest source code.

HTML Interface to Applet


<APPLET CODEBASE="/applets/magelang/AWT-Training/classes/" CODE="ListTest.class" WIDTH=300 HEIGHT=90 ALIGN=CENTER></APPLET>

Java Code


import java.awt.*;

public class ListTest extends java.applet.Applet {

    public void init() {
        String[] items = { "Red", "Orange", "Yellow",
                           "Green", "Blue","Indigo", "Violet" };
        MyList m = new MyList(5, items);
        add(m);
    }
}

class MyList extends List {

    public MyList(int displaySize, String[] elements) {
        super(displaySize, false);  // no multiple selections

        for (int i=0; i<elements.length; i++) {
            addItem(elements[i]);
        }
    }
}