Simple Background Color

Posted on 1998-09-13
Last Modified: 2008-03-17
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) {

Question by:MarkW
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

vendrig earned 20 total points
ID: 1224152
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


Expert Comment

ID: 1224153
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.

Author Comment

ID: 1224154
Got close!

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question