Solved

Simple Background Color

Posted on 1998-09-13
3
1,038 Views
Last Modified: 2008-03-17
How do i set the background color in this code. I am new to Java as you can see.

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

public class StopLight extends Applet {
      //setBackground(Color.blue);
      public void paint(Graphics g) {
            g.drawLine(150,100,150,200);
            g.drawLine(151,100,151,200);
            g.drawLine(152,100,152,200);
            g.drawLine(153,100,153,200);
            g.drawLine(154,100,154,200);
            g.drawLine(155,100,155,200);
            g.setColor(Color.black);
            g.fillRect(133,10,40,97);
            g.setColor(Color.red);
            g.fillOval(140,15,25,25);
            g.setColor(Color.yellow);
            g.fillOval(140,45,25,25);
            g.setColor(Color.green);
            g.fillOval(140,75,25,25);

      }
}
0
Comment
Question by:MarkW
[X]
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
3 Comments
 
LVL 2

Accepted Solution

by:
vendrig earned 20 total points
ID: 1224152
setBackground(Color.pink);
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

0
 
LVL 2

Expert Comment

by:vendrig
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.
0
 
LVL 1

Author Comment

by:MarkW
ID: 1224154
Got it...so close!
0

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