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

HTML Interface to Applet


<APPLET CODEBASE="/applets/magelang/AWT-Training/classes/" CODE="JobTitleListTest.class" WIDTH=180 HEIGHT=120 ALIGN=CENTER></APPLET>

Java Code


import java.awt.*;

public class JobTitleListTest extends java.applet.Applet {

    public void init() {
        JobTitleList test = new JobTitleList();
        add(test);
    }
}

/**
 * Component containing both a Label and a List
 * of possible job titles
 */
class JobTitleList extends FormElement {
    protected List     list;
    protected String   label = "Job Title";

    public JobTitleList() {
        list = new List(5,false);
        list.addItem("President");
        list.addItem("CEO/CFO");
        list.addItem("Vice President");
        list.addItem("Manager");
        list.addItem("CTO");
        list.addItem("Engineer");
        list.addItem("Designer");
        list.addItem("Marketing");
        list.addItem("Programmer");
        list.addItem("Consultant");
        list.addItem("Scientist");
        list.addItem("Support Staff");
        list.addItem("Slacker");
        list.addItem("Webmaster");

        setLayout(new BorderLayout());
        add("North", new Label(label, Label.CENTER));
        add("Center", list);
    }

    public boolean isEmpty() {
        return list.getSelectedIndex() == -1;
    }
    
    /**
     * Return a text representation of this field.
     * This method is required by the FormField interface.
     * @return String the selected text
     */
    public String getContents() {
        return label + "    " + list.getSelectedItem();
    }
}