Skip to Content

Set Foreground Color Of an Applet Window Example

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

Example Output