Java Example Program / Sample Source Code
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.JFrame;
public class ColorExample {
public static void main(String args[]) {
JFrame frame = new JFrame("Color Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JButton button = new JButton("Click to Change Background color");
Color black = new Color(0, 0, 0); // black Color using constructor
// Color yellow = Color.yellow;
// you can also create Color objects from static variables
button.setBackground(black);
frame.add(button, BorderLayout.CENTER);
frame.setSize(400, 300);
frame.setVisible(true);
}
} |
|
|