Solved

Simple Background Color

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
more than one jdk and one jre 1 50
difference between sorce folder and folder in eclipise 3 28
ejb message driven bean mdb creation steps 2 18
jsp error 6 25
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

839 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