Link to home
Start Free TrialLog in
Avatar of MarkW
MarkW

asked on

Simple Background Color

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);

      }
}
ASKER CERTIFIED SOLUTION
Avatar of vendrig
vendrig

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vendrig
vendrig

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.
Avatar of MarkW

ASKER

Got it...so close!