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);
}
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Got it...so close!
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.