Program to set background and foreground color of an Applet
To set the background and foreground color of an applet setBackground(Color c) and setForeground(Color c) methods are used respectively. You have to use these methods in applet's init( ) method. The output of program is shown in OUTPUT section.
PROGRAM
OUTPUT
C:\>javac SetBackColor.java
C:\>appletviewer SetBackColor.java
PROGRAM
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class SetBackColor extends Applet {
public void init()
{
setBackground(Color.cyan);
setForeground(Color.red);
}
public void paint(Graphics g)
{
g.drawString("Hello Java",50,50);
}
}
/*
<applet code="SetBackColor" width=200 height=200>
</applet>
*/
OUTPUT
C:\>javac SetBackColor.java
C:\>appletviewer SetBackColor.java