代码拉取完成,页面将自动刷新
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;
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);
// Generate and draw balloons
// Your work here
for(int i=0;i<balloonCount;i++)
{
int centerx = generator.nextInt(getWidth());
int centery = generator.nextInt(getHeight());
int radius = generator.nextInt(MAX_RADIUS);
Color color = new Color(generator.nextInt(255),generator.nextInt(255),generator.nextInt(255));
Balloon b = new Balloon(centerx,centery,radius,color);
b.draw(g2);
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。