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

TextArea Help

Help is available for each task, or you can go straight to the TextArea source code to see a solution.

Task 1

Create an applet called TextAreaTest. In the init method, create a new instance of the TextArea class, store it as an instance variable, and add it to the applet.

import java.awt.*;

public class TextAreaTest extends java.applet.Applet {
    TextArea disp;
    public void init() {
        disp = new TextArea("click outside TextArea", 5, 30);
        add(disp);
    }
}

Task 2

Define method mouseDown so that when the user clicks outside the TextArea "\npushed mouse..." gets appended to the TextArea.

public class TextAreaTest extends java.applet.Applet {
    ...
    public boolean mouseDown(Event e, int x, int y) {
        disp.appendText("\npushed mouse...");
        return true;
    }
}