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 ChoiceTest source code.

HTML Interface to Applet


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

Java Code


import java.awt.*;

public class ChoiceTest extends java.applet.Applet {

    public void init() {
        MyChoice flavors = new MyChoice();
        add(flavors);
    }
}

class MyChoice extends Choice {

    public MyChoice() {
        addItem("Chocolate");
        addItem("Vanilla");
        addItem("Strawberry");
    }

    public boolean action(Event e, Object color) {
        System.out.println("selected " + color);
        return true;
    }
}