Set Background Color in java
In this example we are going to set color of Background object.
To set the color of object we have to use method
In this we are using Graphics class and
void setBackgroundColor (Color new color );
This method is used to set background color.
paint (Graphics g); This method is used
to paint the applet.
Here first we are importing two packages. Then after we
have write applet tag into comments. In this tag we have pass three arguments
code ,height and width. The code attribute is used to call the applet
class. And Height , width is used for Sizing the window.
Then we have create a class and extends this class with Applet Class to accurse the property of applet. We had override paint method of applet class.
In our example use g.setBackgroundColor(Color new color).
Here new color specifies the new drawing color for background.
//program for set Background color
<applet code="SetBackgroundColor" width=300 height=300>
public class SetBackgroundColor extends Applet
public void paint(Graphics g)
Download Source Code
Output of Example
Show All Comments