import javax.swing.JPanel;
import java.awt.Color;
import java.util.Random;
import java.awt.Graphics;
public class MyPanel extends JPanel {
private int n;
private int cr,cg,cb;
private int r;
private int x,y;
Random random = new Random();
public MyPanel() {
n = random.nextInt(6) + 5;
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.BLACK);
Circle[] circle = new Circle[n];
for (int i=0; i<n; i++) {
cr = random.nextInt(256);
cg = random.nextInt(256);
cb = random.nextInt(256);
// x = random.nextInt(600);
r = random.nextInt(200)+1;
y = random.nextInt(400-2*r);
x = random.nextInt(550-2*r);
circle[i] = new Circle(x, y, r, new Color(cr,cg,cb));
}
for (int i=0; i<n; i++) {
circle[i].draw(g);
}
}
}
Java swing画随机圆
需积分: 38 114 浏览量
2017-10-28
19:38:48
上传
评论 6
收藏 3KB ZIP 举报
xdljh
- 粉丝: 0
- 资源: 1
最新资源
- 基于Python的图像阴影检测与去除源码(高分期末大作业项目).zip
- 基于C++/Qt实现的井字棋游戏
- 基于 Python 编程语言的 Web 框架Django
- Python和Flask实现的基于体检数据的城市公共健康可视分析系统源码+使用说明.zip
- 基于python实现的华为智慧工地-安全帽检测
- buck-boost_2023-12-16_12-12-13.eprj
- 后端开发关于数据库和API开发的介绍
- 机器学习和数据挖掘课程设计-米其林餐厅数据挖掘管理系统源码+使用文档说明.zip
- html html html展示我与ai的对化
- 数据结构课程设计-全国交通出行咨询模拟系统C语言实现源码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈