Solved

Simple Background Color

Posted on 1998-09-13
3
1,037 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ejb stateless example 2 66
eclipse console opening separately 2 48
passing enum to a method 4 49
Java Inheritance super keyword use 8 71
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

732 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