动漫人物
RandomCircle.java---------------------------------------------------------------------------------- import java.applet.Applet;import java.awt.Color;import java.awt.Graphics; public class RandomCircle extends Applet implements Runnable{ private static final long serialVersionUID = 1L; private String sleep; private volatile Thread timer; private Color color; private int radius; private int width = 300, height = 300, x, y; @Override public void init () { sleep = null == getParameter ("sleep") ? "500" : getParameter ("sleep"); change (); resize (width, height); } @Override public void update ( Graphics graphics ) { draw (graphics); } @Override public void paint ( Graphics graphics ) { draw (graphics); } private void draw ( Graphics graphics ) { graphics.clearRect (0, 0, width, height); graphics.setColor (color); // 变到150直径时擦除,重新再出现圆 radius += 10; if (radius >= 150) { change (); } graphics.fillArc (x, y, radius, radius, 0, 360); graphics.dispose (); } private void change () { radius = 0; // 位置随机 x = (int) ( Math.random () * ( width / 2 - radius ) ); y = (int) ( Math.random () * ( height / 2 - radius ) ); // 颜色随机 int r = (int) ( Math.random () * 255 ); int g = (int) ( Math.random () * 255 ); int b = (int) ( Math.random () * 255 ); color = new Color (r, g, b); } @Override public void start () { timer = new Thread (this); timer.start (); } @Override public void stop () { timer = null; } @Override public void run () { Thread me = Thread.currentThread (); while (timer == me) { try { Thread.sleep (Integer.parseInt (sleep)); } catch (NumberFormatException ignore) {} catch (InterruptedException ignore) {} repaint (); } } public String getAppletInfo () { return "Title: java画随机的圆 \n" + "Author: yugi111, 2014 \n" + "A simple circle."; } public String[][] getParameterInfo () { String[][] info = { { "<1>", "功能要求:", "实现简单的动画"}, { "<2>", "具体要求:", "自动出现由小到大变换的圆,位置与颜色随机,变到150直径时擦除,重新再出现圆;"}, { "<3>", "变换速度有HTML文件传入的参数控制(控制sleep时间)。", "界面要求:用Java Applet实现。"} }; return info; }} ---------------------------------------------------------------------------------RandomCircle.html--------------------------------------------------------------------------------- <!DOCTYPE HTML><HTML> <HEAD> <meta charset="UTF-8" /> <TITLE>java画随机的圆</TITLE> </HEAD> <BODY> <h1>java画随机的圆</h1> <hr> <applet code="RandomCircle.class" width=300 height=300> alt="Your browser understands the <APPLET> tag but isn't running the applet, for some reason." Your browser is completely ignoring the <APPLET> tag! <param name="sleep" value="500"> </applet> <p> <1> 功能要求:实现简单的动画。<br /> <2> 具体要求:自动出现由小到大变换的圆,位置与颜色随机,变到150直径时擦除,重新再出现圆;<br /> <3> 变换速度有HTML文件传入的参数控制(控制sleep时间)。界面要求:用Java Applet实现。 <p> <applet code="RandomCircle.class" width=300 height=300> <param name="sleep" value="300"> </applet> <p> <hr> <a href="RandomCircle.java">源代码</a>. </BODY></HTML> ------------------------------------------------------------------------------RandomCircle.class------------------------------------------------------------------------------见附件 ------------------------------------------------------------------------------操作如下图所示:12---------------------------------------------------效果图: