Written by Sai Sandeep Thota on November 17, 2013 in Java > Programming

How to change Background and Foreground color in Applet

GET ALERTS:

Get our Latest updates delivered to your mailbox!

Today in this tutorial we will learn 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()
	{
		setForeground(Color.white);
		setBackground(Color.blue);
	}

	public void paint(Graphics g)
	{
		g.drawString("ProgrammingUnit", 10, 100);
	}
}

Output:

change_appletColor_java

Download Source Code

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: