Explain how to set the background color within the applet area.
- In an applet, by default it has gray background when displayed in a browser.
- If you want to change the background color of an applet, then you can call the setBackground(java.awt.Color) method.
- Using the setBackground(java.awt.Color) method you can choose whichever color you want.
Example:import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class BackgroundColorApplet extends Applet
{
public void init()
{
setBackgroundColor(Color.YELLOW);
}
}
- In the above example, defining the background color in the init() method will change the color as soon as the applet initialized. The BackgroundColorApplet class extends from the Applet class, for accessing these classes you have to import the applet packages at the start of the program.
You can set the background color of an applet in the following manner:<applet code="MyApplet.class" width="100" height="100">
<param name="background-color" value="#ffffff">
<param name="foreground-color" value="#000000">
</applet>