Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Graphics;
  3.  
  4. import javax.swing.JFrame;
  5. import javax.swing.JPanel;
  6.  
  7. public class Experiment extends JPanel {
  8.  
  9.  
  10. public void paintComponent(Graphics g) {
  11. int R = (int) (Math.random() * 255);
  12. int G = (int) (Math.random() * 255);
  13. int B = (int) (Math.random() * 255);
  14. g.setColor(new Color(R,G,B));
  15. drawCrazy(g);
  16. repaint();
  17.  
  18. }
  19. public static void main(String[] args) {
  20. // TODO Auto-generated method stub
  21. JFrame window = new JFrame("GRAPHICS");
  22. window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  23.  
  24. window.getContentPane().add(new Experiment());
  25. window.setBounds(300,300,300,300);
  26. window.setVisible(true);
  27. window.setResizable(false);
  28.  
  29. }
  30.  
  31.  
  32. public void drawCrazy(Graphics g) {
  33. int x1 = (int) (Math.random() * 300);
  34. int y1 = (int) (Math.random() * 300);
  35. int width = (int) (Math.random() * 300);
  36. int height = (int) (Math.random() * 300);
  37.  
  38. //g.fillRect(x1, y1, width, height);
  39. g.fillOval(x1, y1, width, height);
  40.  
  41.  
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement