How to change an applet background color?

DeeKay August 27, 2011 at 1:31 am · java.applet

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.

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

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

/**
 * Created by http://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);
    }
}