多彩烟花
来源:互联网 发布:php技术文档模板 编辑:程序博客网 时间:2024/05/16 01:54
/** * 多彩烟花绘制 * @author Administrator * */public class FireWorks extends JFrame{ private static final long serialVersionUID = 1L; public FireWorks(){ super("多彩烟花"); this.setSize(800, 600); JPanel pane=new JPanel(); pane.setBackground(new Color(0x0)); this.setContentPane(pane); this.setVisible(true); this.setLocationRelativeTo(null); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); start(); } public void start(){ final ExecutorService threadPool=Executors.newFixedThreadPool(8); this.addMouseListener( new MouseAdapter(){ public void mouseClicked(final MouseEvent e){ threadPool.execute( new Runnable(){ public void run(){ drawFire(e.getX(),e.getY()); drawFireWorks(e.getX(),e.getY()); } } ); } } ); } /** * 烟花发射 */ public void drawFire(int x,int y){ Graphics g=this.getGraphics(); int x_start=x; int y_start=550; Random color=new Random(); while(y_start>=y){ for(int i=0;i<11;i++){ if(i!=0 && (y_start-i*5)>=y){ g.setColor( new Color(color.nextInt(256),color.nextInt(256),color.nextInt(256)) ); }else{ g.setColor( new Color(0x0) ); } g.fillOval(x_start, y_start-i*5, 5, 5); } y_start-=5; try{ Thread.sleep(25); }catch(Exception e){ } } } /** * 烟花绘制 */ public void drawFireWorks(int x,int y){ Graphics g=this.getGraphics(); int x_start=x; int y_start=y; Random color=new Random(); for(int i=0;i<20;i++){ for(int j=0;j<4;j++){ if(j!=0 && (i+j)<15){ g.setColor( new Color(color.nextInt(256),color.nextInt(256),color.nextInt(256)) ); }else{ g.setColor( new Color(0x0) ); } g.drawOval(x_start-(i+j+3)*5, y_start-(i+j+3)*5, (i+j+3)*10, (i+j+3)*10); } try{ Thread.sleep(60); }catch(Exception e){ } if(i>3){ drawString(x,y,i); } } } /** *画字符串 */ public void drawString(int x,int y,int time){ Graphics g=this.getGraphics(); Random ran=new Random(); String[] message={"恭喜发财","财源滚滚","心想事成","事业有成"}; if(time!=19){ g.setColor( new Color(ran.nextInt(256),ran.nextInt(256),ran.nextInt(256)) ); }else{ g.setColor( new Color(0x0) ); } g.drawString(message[(int)(x+y)%message.length], x-20, y); } public static void main(String[] args) { new FireWorks(); }}
阅读全文
0 0
- 多彩烟花
- 烟花
- 烟花
- 烟花
- 烟花
- 烟花
- 烟花
- 多彩旅行
- 多彩助手
- 烟花烫
- 模拟烟花
- 烟花一月
- 绚烂烟花
- 《烟花三月》
- 烟花代码
- 烟花三月
- 烟花效果
- 烟花三月
- iOS 视频录制 包括预览图片与视频还有写入自己自定义的App相册 微信小视频
- R-CNN,SPP-NET, Fast-R-CNN,Faster-R-CNN, YOLO,系列深度学习检测方法
- 网络---端口
- python中Matplotlib库显示界面中进行鼠标交互绘制操作
- Gilde加载图片
- 多彩烟花
- P1996 约瑟夫问题
- 高性能MYSQL(查询优化)
- 微服务,够了 (对微服务的一些客观正名和经验指导)
- springboot整合springSecurity出现的问题,post,delete,put无法使用
- ios 判断当前页面从哪个页面跳转过来的(上个界面是哪个ViewController)
- [PPPOE]PPPD源码分析
- 游戏UI框架设计(三) : 窗体的层级管理
- Spring Cloud 学习之旅 --- 随机端口启动多实例