Skip to Content

Get Foreground Color Of an Applet Window Example

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

Example Output