Java程序设计:图形与多媒体处理(1)

本文主要介绍了Java的图形设计以及多媒体处理,源码作者也做了详细的注释,对于初学者应该不难。

详细请看下文

同心圆效果图:

  1. 1. /**
  2. 2.  *程序要求:新建一个600\*600像素的应用程序窗口,并在窗口中绘制5个不同颜色的同心圆,
  3. 3.  *所有圆心都是屏幕的中心点,相邻两个圆直接的半径相差50像素
  4. 4.  *效果图如下图所示(颜色随机设置),源程序保存为Ex7\_1.java。
  5. 5.  *作者:wwj
  6. 6.  *日期:2012/4/25
  7. 7.  *功能:显示一个有5个不同颜色的同心圆
  8. 8.  */
  9. 9.  import javax.swing.\*;
  10. 10.  import java.awt.\*;
  11. 11.  import java.awt.Color;
  12. 12.  public class Ex7\_1 extends JFrame
  13. 13.  {
  14. 14.      int red,green,blue;
  15. 15.      Color color;
  16. 16.      public Ex7\_1()
  17. 17.      {
  18. 18.          super("一个有5个不同颜色的同心圆");    //显示窗口名称
  19. 19.          setSize(600,600);                      //设置窗口大小
  20. 20.          setVisible(true);                      //设置为可见
  21. 21.          setDefaultCloseOperation(JFrame.EXIT\_ON\_CLOSE);//设置窗口关闭动作
  22. 22.      }
  23. 23.      public void paint(Graphics g)
  24. 24.      {
  25. 25.          //第一个圆
  26. 26.         red=(int)(Math.random()\*255);
  27. 27.         green=(int)(Math.random()\*255);
  28. 28.         blue=(int)(Math.random()\*255);
  29. 29.         color=new Color(red,green,blue);
  30. 30.         g.setColor(color);
  31. 31.         g.fillOval(175,175,250,250);
  32. 32.         //第二个圆
  33. 33.         red=(int)(Math.random()\*255);
  34. 34.         green=(int)(Math.random()\*255);
  35. 35.         blue=(int)(Math.random()\*255);
  36. 36.         color=new Color(red,green,blue);
  37. 37.         g.setColor(color);
  38. 38.         g.fillOval(200,200,200,200);
  39. 39.         //第三个圆
  40. 40.         red=(int)(Math.random()\*255);
  41. 41.         green=(int)(Math.random()\*255);
  42. 42.         blue=(int)(Math.random()\*255);
  43. 43.         color=new Color(red,green,blue);
  44. 44.         g.setColor(color);
  45. 45.         g.fillOval(225,225,150,150);
  46. 46.         //第四个圆
  47. 47.         red=(int)(Math.random()\*255);
  48. 48.         green=(int)(Math.random()\*255);
  49. 49.         blue=(int)(Math.random()\*255);
  50. 50.         color=new Color(red,green,blue);
  51. 51.         g.setColor(color);
  52. 52.         g.fillOval(250,250,100,100);
  53. 53.         //第五个圆
  54. 54.         red=(int)(Math.random()\*255);
  55. 55.         green=(int)(Math.random()\*255);
  56. 56.         blue=(int)(Math.random()\*255);
  57. 57.         color=new Color(red,green,blue);
  58. 58.         g.setColor(color);
  59. 59.         g.fillOval(275,275,50,50);
  60. 60.      }
  61. 61.      public static void main(String\[\] args)
  62. 62.      {
  63. 63.          Ex7\_1 e = new Ex7\_1();
  64. 64.      }
  65. 65.  }

查看Java程序设计:图形与多媒体处理(2)

原文链接:http://blog.csdn.net/wwj_748/article/details/7522672


» 本文链接:https://blog.apires.cn/archives/762.html
» 转载请注明来源:Java地带  » 《Java程序设计:图形与多媒体处理(1)》

» 本文章为Java地带整理创作,欢迎转载!转载请注明本文地址,谢谢!
» 部分内容收集整理自网络,如有侵权请联系我删除!

» 订阅本站:https://blog.apires.cn/feed/

标签: Java程序设计, Java图形编程, Java多媒体处理技术

添加新评论