Answer:

The completed applet is given below.

Hello JApplet

The X and Y values in drawString place the lower left corner of the 'H' in the center of the drawing area. If you want the center of the string to be in the center of the drawing area, you would need to determine the dimensions of the string and do some calculation. There are methods that help you do this, but let's skip those details for now.

// Put "Hello" at the center of a 300 by 150 drawing area
//
import javax.swing.JApplet;
import java.awt.*;

public class AnotherHello extends JApplet
{
  public void paint ( Graphics gr )
  { 
    setBackground( Color.lightGray );
    gr.drawString("Hello", 150, 75 );
   }
}

Here is what the applet does with your Web browser:

Not all browsers can run applets. If you see this message, yours can not.

QUESTION 6: