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();
}
}
|