source code: randomcolor.java

    import java.awt.*;
    import java.awt.event.*;
 class randomcolor extends Frame
{
 Color col=Color.green;  
 public randomcolor(){ 
setLayout(null);     

Button b1=new Button("randomcolor");//create button 
    b1.setBounds(100,80,100, 40); 
add(b1);//adding button on frame 
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
System.out.println("testing");
int r,g,b;
r=(int)(255*Math.random());
g=(int)(255*Math.random());
b=(int)(255*Math.random());
col=new Color(r,g,b);
repaint();
}
});
    } 
public void paint(Graphics g)
{
g.setColor(col);
g.fillRect(50,200,175,50);
}
    public static void main(String[] args) { 
randomcolor f=new randomcolor();
f.setSize(400,500); 
 f.setVisible(true); 
    }
}  

output: