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

HTML Interface to Applet


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

Java Code


import java.awt.*;

public class RadioButtonsTest extends java.applet.Applet {

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

/**
 * Component containing a group of Checkboxes
 */
class RadioButtons extends FormElement {

    protected CheckboxGroup cbg;
    protected String        label = "Java for: ";

    public RadioButtons() {
        setLayout(new FlowLayout());
        add(new Label(label));
        cbg = new CheckboxGroup();
        add(new Checkbox("C++ Programmers", cbg, true));
        add(new Checkbox("Procedural Programmers", cbg, false));
    }

    /**
     * Return a text representation of this field.
     * This method is required by the FormElement interface.
     * @return String the selected text
     */
    public String getContents() {
        return label + "    " + cbg.getCurrent().getLabel();
    }
}