Advertisement
demoraesr89

Clouds in the Air

Aug 2nd, 2016
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Graphics;
  3. import java.awt.Graphics2D;
  4.  
  5. import javax.swing.JComponent;
  6. import javax.swing.JFrame;
  7.  
  8. public class Clouds
  9. {
  10. public static void main(String[] args)
  11. {
  12. JFrame frame = new JFrame();
  13. frame.setSize(500,500);
  14. frame.setVisible(true);
  15. //frame.setBackground(Color.blue);
  16. Cloud myCloud = new Cloud(300, 300);//component
  17.  
  18. frame.getContentPane().add(myCloud);
  19. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  20. }
  21. } //class cloud ends here (that is one class)
  22.  
  23. class Cloud extends JComponent
  24. {
  25. private int posX, posY;
  26.  
  27. public Cloud(int x, int y){
  28. this.posX = x;
  29. this.posY = y;
  30. }
  31.  
  32. public void paint(Graphics g)
  33. {
  34. Graphics2D g2d = (Graphics2D)g; //remember that casting is here
  35.  
  36. int w = getWidth();
  37. int h = getHeight();
  38. g2d.setColor(Color.blue);
  39. g2d.fillRect(0, 0, w, h);
  40.  
  41. g.setColor(Color.white);
  42.  
  43. g.fillOval(posX, posY, 110, 50);
  44.  
  45. for(int i = 0; i < 5; i++)
  46. {
  47. int x = (int)(Math.random() * 110 + posX);
  48. int y = (int)(Math.random() * 50 + posY);
  49. g.fillOval(x, y, 110, 50);
  50. }
  51. /*
  52. g.setColor(Color.white);
  53. g.fillOval(300, 300, 75, 50);
  54. for(int i = 0; i < 20; i++)
  55. {
  56. int x = (int)(Math.random()*350);
  57. int y = (int)(Math.random()*325);
  58. g.setColor(Color.white);
  59. g.fillOval(x, y, 75, 50);
  60.  
  61. }
  62.  
  63. */
  64. g2d.dispose();
  65.  
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement