Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Graphics;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- public class Experiment extends JPanel {
- public void paintComponent(Graphics g) {
- int R = (int) (Math.random() * 255);
- int G = (int) (Math.random() * 255);
- int B = (int) (Math.random() * 255);
- g.setColor(new Color(R,G,B));
- drawCrazy(g);
- repaint();
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- JFrame window = new JFrame("GRAPHICS");
- window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- window.getContentPane().add(new Experiment());
- window.setBounds(300,300,300,300);
- window.setVisible(true);
- window.setResizable(false);
- }
- public void drawCrazy(Graphics g) {
- int x1 = (int) (Math.random() * 300);
- int y1 = (int) (Math.random() * 300);
- int width = (int) (Math.random() * 300);
- int height = (int) (Math.random() * 300);
- //g.fillRect(x1, y1, width, height);
- g.fillOval(x1, y1, width, height);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement