Change Foreground Color Of Label Example
- /*
- Change Foreground Color Of Label Example
- This java example shows how to change foreground color of a label using
- setForeground method.
- */
- import java.applet.Applet;
- import java.awt.Color;
- import java.awt.Label;
- /*
- <applet code="ChangeForegroundColor" width=100 height=200>
- </applet>
- */
- public class ChangeForegroundColor extends Applet{
- public void init(){
- //create labels
- Label label1 = new Label("Label 1");
- Label label2 = new Label("Label 2");
- //add labels
- add(label1);
- add(label2);
- /*
- * To set foreground color of a label use
- * void setForeground(Color c)
- * method.
- */
- label1.setForeground(Color.blue);
- label2.setForeground(Color.magenta);
- }
- }
Example Output




