Advertisement
advictoriam

Untitled

Nov 22nd, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1. // NOTE: CODECHECK.IT PROBLEM BROKEN
  2. import javax.swing.JComponent;
  3. import java.awt.Graphics;
  4. import java.awt.Graphics2D;
  5. import java.awt.Color;
  6. import java.awt.Rectangle;
  7. import java.util.Random;
  8.  
  9. /**
  10.    This class displays a number of balloons.
  11. */
  12. public class BalloonComponent extends JComponent
  13. {
  14.    private int balloonCount;
  15.    
  16.    /**
  17.       Constructor for a BalloonComponent with a number of balloons
  18.       @param n the number of balloons to show
  19.    */
  20.    public BalloonComponent(int n)
  21.    {
  22.        balloonCount = n;
  23.    }
  24.        
  25.    public void paintComponent(Graphics g)
  26.    {
  27.       final Color SKY_BLUE = new Color(165,218,239);
  28.       final int MAX_RADIUS = 30;
  29.       final int SCREEN_SIZE = 400;
  30.  
  31.       Graphics2D g2 = (Graphics2D) g;
  32.       // Draw the sky
  33.       Rectangle sky = new Rectangle (0, 0 , getWidth(), getHeight());
  34.       g2.setColor(SKY_BLUE);
  35.       g2.fill(sky);
  36.       // Use this random number generator
  37.       Random generator = new Random(42);
  38.  
  39.       for(int i = 0; i < balloonCount; i++)
  40.       {
  41.          Color c = new Color(generator.nextFloat(), generator.nextFloat(), generator.nextFloat());
  42.          Balloon b = new Balloon(generator.nextInt(SCREEN_SIZE), generator.nextInt(SCREEN_SIZE), generator.nextInt(MAX_RADIUS), c);
  43.          b.draw(g2);        
  44.       }
  45.  
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement