By default the applet will usually have a grey background when displayed in a web browser. If you want to change it then you can call the setBackground(java.awt.Color)
method 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 BackgroundColorApplet extends Applet {
public void init() {
// Here we change the default grey color background of an
// applet to yellow background.
setBackground(Color.YELLOW);
}
public void paint(Graphics g) {
g.setColor(Color.BLACK);
g.drawString("Applet background example", 0, 50);
}
}
Latest posts by Wayan (see all)
- How do I install Calibri font in Ubuntu? - January 24, 2021
- How do I create a generic class in Java? - January 1, 2021
- How do I convert java.util.TimeZone to java.time.ZoneId? - April 25, 2020