import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.event.*;
import java.awt.*;
public class RandomColor extends JFrame implements ActionListener {
private JPanel jContentPane = null;
private JButton jButton = null;
public static void main(String[] args){
RandomColor myrc = new RandomColor();
}
/**
* This is the default constructor
*/
public RandomColor() {
super();
initialize();
this.setVisible(true);
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(300, 200);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.setBackground(new java.awt.Color(238,238,85));
jContentPane.add(getJButton(), java.awt.BorderLayout.NORTH);
}
return jContentPane;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setText("Randomize");
jButton.addActionListener(this);
}
return jButton;
}
public void actionPerformed(ActionEvent e) {
int rval = (int)Math.floor(Math.random() * 256);
int gval = (int)Math.floor(Math.random() * 256);
int bval = (int)Math.floor(Math.random() * 256);
Color c = new Color(rval,gval,bval);
this.jContentPane.setBackground(c);
}
}