为了账号安全,请及时绑定邮箱和手机立即绑定

想要实现一个简单的动画,要求自动出现由小到大变换的圆,请问该怎么做?

想要实现一个简单的动画,要求自动出现由小到大变换的圆,请问该怎么做?

MM们 2022-05-19 12:15:39
功能要求:实现简单的动画。具体要求:自动出现由小到大变换的圆,位置与颜色随机,变到150直径时擦除,重新再出现圆;变换速度有HTML文件传入的参数控制(控制sleep时间)。界面要求:用Java Applet实现。
查看完整描述

1 回答

?
动漫人物

TA贡献1815条经验 获得超10个赞


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 (00, width, height);        graphics.setColor (color);        // 变到150直径时擦除,重新再出现圆        radius += 10;        if (radius >= 150)        {            change ();        }        graphics.fillArc (x, y, radius, radius, 0360);        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 &lt;APPLET&gt; tag but isn't running the applet, for some reason."      Your browser is completely ignoring the &lt;APPLET&gt; tag!      <param name="sleep" value="500">    </applet>      <p>       &lt;1&gt; 功能要求:实现简单的动画。<br />       &lt;2&gt; 具体要求:自动出现由小到大变换的圆,位置与颜色随机,变到150直径时擦除,重新再出现圆;<br />       &lt;3&gt; 变换速度有HTML文件传入的参数控制(控制sleep时间)。界面要求:用Java Applet实现。      <p>        &lt;applet code="RandomCircle.class" width=300 height=300&gt;        &lt;param name="sleep"  value="300"&gt;        &lt;/applet&gt;      <p>      <hr>      <a href="RandomCircle.java">源代码</a>.  </BODY></HTML> ------------------------------------------------------------------------------RandomCircle.class------------------------------------------------------------------------------见附件 ------------------------------------------------------------------------------操作如下图所示:

12---------------------------------------------------效果图:




查看完整回答
反对 回复 2022-05-23
  • 1 回答
  • 0 关注
  • 319 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号