How to change an applet background color?

Applet’s default background color is Grey. If you want to change it then you need to call the setBackground(java.awt.Color) and choose the color you want. Defining the background color in the init method will change the color as soon as the applet initialized.

[java]
/****************************************************************************************
* Created on 08-2011 Copyright(c) https://kodehelp.com All Rights Reserved.
****************************************************************************************/
package com.kodehelp.java.applet;

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

/**
* Created by https://kodehelp.com
* Date: 8/26/11
*/
public class ChangeAppletBgk extends Applet{
public void init(){
setBackground(Color.BLUE);
}

public void paint(Graphics graphics){
graphics.setColor(Color.BLACK);
graphics.drawString("Applet background example", 0, 50);
}
}
[/java]