Change Button Foreground Color Example
- /*
- Change Button Foreground Color Example
- This java example shows how to change button foreground color using
- AWT Button class.
- */
- import java.applet.Applet;
- import java.awt.Button;
- import java.awt.Color;
- /*
- <applet code="ChangeButtonForegroundExample" width=200 height=200>
- </applet>
- */
- public class ChangeButtonForegroundExample extends Applet{
- public void init(){
- //create buttons
- Button button1 = new Button("Button 1");
- Button button2 = new Button("Button 2");
- /*
- * To change foreground color of a button use
- * setForeground(Color c) method.
- */
- button1.setForeground(Color.magenta);
- button2.setForeground(Color.blue);
- //add buttons
- add(button1);
- add(button2);
- }
- }
Example Output




