Saturday, 3 August 2013

Java Applets :How to change button background in applets

// siddhu vydyabhushana // 3 comments
How to change button background in applets

change button background in applets:
/*
        Change Button Background Color Example
        This java example shows how to change button background color using
        AWT Button class.
*/
 
import java.applet.Applet;
import java.awt.Button;
import java.awt.Color;
 
 
/*
<applet code="ChangeButtonBackgroundExample" width=200 height=200>
</applet>
*/
public class ChangeButtonBackgroundExample extends Applet{
 
        public void init(){
               
                //create buttons
                Button button1 = new Button("Button 1");
                Button button2 = new Button("Button 2");
               
                /*
                 * To change background color of a button use
                 * setBackground(Color c) method.
                 */
               
                button1.setBackground(Color.red);
                button2.setBackground(Color.green);
               
                //add buttons
                add(button1);
                add(button2);
        }
}
Output:

3 comments: