Solved

Simple Background Color

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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…
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 …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now