Skip to Content

Set Background Color Of an Applet Window Example

  1. /*
  2.         Set Background Color Of an Applet Window Example
  3.         This java example shows how to set background color of an Applet window using
  4.         setBackground method of component class.
  5. */
  6.  
  7. /*
  8. <applet code="SetBackgroundColorExample" width=200 height=200>
  9. </applet>
  10. */
  11.  
  12.  
  13. import java.applet.Applet;
  14. import java.awt.Color;
  15. import java.awt.Graphics;
  16.  
  17. public class SetBackgroundColorExample extends Applet{
  18.  
  19.         public void paint(Graphics g){
  20.                 /*
  21.                  * Set background color of an applet using
  22.                  * void setBackground(Color c) method.
  23.                  */
  24.                
  25.                 setBackground(Color.red);
  26.         }
  27. }

Example Output