You are on page 1of 2

How to change Background and Foreground color in Applet.

We have two predefined methods in Java called setBackground() and setForeground() which are used for setting Background and
Foreground of an Applet Window respectively.

The Color class defines the constant values: Color.white, Color.grey, Color.blue, Color.red, Color.white

How to change Background and Foreground color in Applet

/* ProgrammingUnit.com */

import java.awt.*;

import java.applet.*;

/*

<applet code="appletColor" width="400" height="200">

</applet>

*/

public class appletColor extends Applet {

public void init()

1
setForeground(Color.white);

setBackground(Color.blue);

public void paint(Graphics g)

g.drawString("ProgrammingUnit", 10, 100);

Output

You might also like