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:
Embedded Java applet removed: modern browsers do not support Java applets. The surrounding source code is retained for historical study.
QUESTION 6:
- What should the source file be named for this applet?
- What file will be created when the source file is compiled?