1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
/* 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
Add Comment