• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1049
  • Last Modified:

Simple Background Color

How do i set the background color in this code. I am new to Java as you can see.

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

public class StopLight extends Applet {
      public void paint(Graphics g) {

  • 2
1 Solution
This method applies to a component, in this case "this" (your applet).You could also set the background color of panels etc..
You can find more details and other interesting methods at http://java.sun.com:80/products/jdk/1.1/docs/api/java.awt.Component.html

When I refreshed I saw you had the right method but commented out...
Why? And why was it outside the paint method? If you have an init method, that may be the best place to put the setBackground.
MarkWAuthor Commented:
Got it...so close!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now