BASIC 2 HIFI PROGRAM ...
ALL HERE

Monday, 22 December 2014

GENERATE RANDOMCOLOR IN JAVA

import java.awt.*;
import javax.swing.*;

class random_color extends JPanel {

public void paintComponent(Graphics g)
{
g.fillRect(0,0,this.getWidth(),this.getHeight());

int red =(int)(Math.random()*255);
int green=(int)(Math.random()*255);
int blue=(int)(Math.random()*255);
Color randomColor=new Color(red,green,blue) ;
g.setColor(randomColor);
g.fillOval(70,70,100,100);
}
}

public class randomly{
public static void main(String[] args)
{
JFrame frame=new JFrame();
frame.getContentPane().add(new random_color());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800,800);
frame.setVisible(true);
}
}

No comments:

Post a Comment