Step 4

A better approach would be to use two panels: one for the UI components and the other for drawing. This is done in the code that follows, using the applet's inherent panel and a new panel, called panel.

Example Applet

import java.applet.Applet;
import java.awt.*;

public class step4 extends Applet{

// separates components from drawing area

TextArea ta = new TextArea ("My Text Area", 5, 40);
Button button = new Button ("Button");
Panel panel = new Panel ();

  public void init ( ){

    setBackground (Color.white);
    setForeground (Color.red);

    add (ta);
    add (button);

    panel.setBackground (Color.blue);
    add (panel);

  } // end init

}// end step4

Run the applet

Discussion

In this program, the new panel was colored blue, so that we could see it. Notice that when it appears, to the right of the two UI components, it is pretty small.