TextArea Questions

 

  1. Type in the below code.

import java.awt.*;
import java.applet.*;
import javax.swing.*;
public class testText extends Applet
{
    JTextArea TA;
    public void init ()
    {
        TA = new JTextArea ("Hello, ");
        add (TA);
    }
}

 

(A)   What appears on the screen?

(B)    How do you declare a TextArea?

(C)    What does the call to the constructor look like?

(D)    How to you add a TextArea to the screen?

  1. Add this line at the bottom of the init method.

TA.append("how are you? ");

(A)   How does this change the screen?

(B)    Write the code to add “I really want to know” to the screen.

  1. Add this line to the bottom of the init method.

TA.append("\n");

TA.append("I am fine. ");

(A)   How does this change what is on the screen?

(B)    What does ‘\n’ do?

  1. Change the constructor in the following ways. What does each one do?

(A)   TA= new JTextArea(“Hello”, 10, 20);

(B)    TA = new JTextArea(10,20);

  1. What does TA.setText(""); do?

  2. Go to the Help File and see if you can use it to figure out how to change the constructor call so that the TextArea has no scroll bars.