How do I change an applet background color?
Category: java.applet, viewed: 577 time(s).
By default the applet will have a gray background. If you want to change it then you can 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.
package org.kodejava.example.applet;
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class WhiteBackgroundApplet extends Applet {
public void init() {
//
// Here we change the default gray color background of an applet to
// white background.
//
setBackground(Color.WHITE);
}
public void paint(Graphics g) {
g.setColor(Color.BLACK);
g.drawString("Applet background example", 0, 50);
}
}
|