Skip to Content

Get Background Color Of an Applet Window Example

  1. /*
  2.         Get Background Color Of an Applet Window Example
  3.         This java example shows how to get background color of an Applet window using
  4.         getBackground method of component class.
  5. */
  6.  
  7. /*
  8. <applet code="GetBackGroundColorExample" 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 GetBackGroundColorExample extends Applet{
  18.        
  19.         public void paint(Graphics g){
  20.                 //get background color using getBackground method
  21.                 Color c = getBackground();
  22.                 g.drawString(c.toString(),50,50);
  23.         }
  24. }

Example Output