Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // NOTE: CODECHECK.IT PROBLEM BROKEN
- import javax.swing.JComponent;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Color;
- import java.awt.Rectangle;
- import java.util.Random;
- /**
- This class displays a number of balloons.
- */
- public class BalloonComponent extends JComponent
- {
- private int balloonCount;
- /**
- Constructor for a BalloonComponent with a number of balloons
- @param n the number of balloons to show
- */
- public BalloonComponent(int n)
- {
- balloonCount = n;
- }
- public void paintComponent(Graphics g)
- {
- final Color SKY_BLUE = new Color(165,218,239);
- final int MAX_RADIUS = 30;
- final int SCREEN_SIZE = 400;
- Graphics2D g2 = (Graphics2D) g;
- // Draw the sky
- Rectangle sky = new Rectangle (0, 0 , getWidth(), getHeight());
- g2.setColor(SKY_BLUE);
- g2.fill(sky);
- // Use this random number generator
- Random generator = new Random(42);
- for(int i = 0; i < balloonCount; i++)
- {
- Color c = new Color(generator.nextFloat(), generator.nextFloat(), generator.nextFloat());
- Balloon b = new Balloon(generator.nextInt(SCREEN_SIZE), generator.nextInt(SCREEN_SIZE), generator.nextInt(MAX_RADIUS), c);
- b.draw(g2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement