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.

/****************************************************************************************
 * 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);
    }
}

Please Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.