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

HTML Interface to Applet


<APPLET CODEBASE="/applets/magelang/AWT-Training/classes/" CODE="CommentBoxTest.class" WIDTH=420 HEIGHT=100 ALIGN=CENTER></APPLET>

Java Code


import java.awt.*;

public class CommentBoxTest extends java.applet.Applet {

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

/**
 * Component containing both a Label and a TextArea
 */
class CommentBox extends FormElement {

    protected TextArea text;
    protected String   label = "Comments";

    public CommentBox() {
        setLayout(new BorderLayout());

        text = new TextArea(3, 55);

        add("North",  new Label(label, Label.CENTER));
        add("Center", text);
    }

    /**
     * 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 + "    " + text.getText();
    }
}