R4R Java SourceCode Set Back Ground Color

Set Back Ground Color 

In this example we going to explain how we can set the background  color of an applet. We need to import two packages java.applet.Applet and java.awt.*. The java.applet.Applet is imported to make applet window and used its two methods eg. paint(Graphics g) and init().

In init() method we define the initial property which we required in application. The paint()  method is used to paint the window.
We are using here two methods first one is setBackground(int color ) it is method of Applet class and second one is drawString(String a,int x, int y) it is method of Graphics class .As name refer drawString(String str,int x,int y) is used to draw the string. We are using an other method resize(int h,int w).It is used for resize the applet window.


import java.applet.Applet;
import java.awt.*;

public class SetBackGroundColor extends Applet {
	public void init() {
		resize(300, 300);

	public void paint(Graphics g) {
		g.drawString("R4R JAVA APPLET BACKGROUND EXAMPLE", 10, 20);

//<applet code="SetBackGroundColor.class" width=200 height=300>

Download Source File

Output of This Example