有关于JAVA的动画的程序

Gzd2003 2008-01-04 08:57:39
有关于JAVA的动画的一题,下面是画一个带填充色的矩形并让它在屏幕上从左向右走动。不知道程序哪里有问题,麻烦各位指点。
import java.applet.Applet;
import java.awt.*;
public class juxing extends Applet implements Runnable{
Image im;
Thread t=null;
public void init(){
setBackground(Color.white);
}
public void start(){
Thread t=new Thread(this);
t.start();
}
public void run(){
try{
while(true){
t.sleep(1000);
repaint();
}
}catch(InterruptedException e){}
}

public void paint(Graphics g){

for(int i=0;i<240;i++){
g.fillRect(i,80,70,40);
g.drawImage(im,i,80,this);
}
}
}
...全文
112 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Gzd2003 2008-01-05
  • 打赏
  • 举报
回复
谢谢。
cursor_wang 2008-01-05
  • 打赏
  • 举报
回复
帮你改好了.test.html要这样写
<applet code="juxing.class" width="300" height="300">
</applet>

import   java.applet.Applet; 
import java.awt.*;
public class juxing extends Applet implements Runnable{
int i;
Image im;
Thread t=null;
public void init(){
setBackground(Color.white);
}
public void start(){
t=new Thread(this);
t.start();
}
public void run(){
while(true)
{
try
{
Thread.currentThread().sleep(1000);
i=i+10;
if(i>300)
i=0;
repaint();
}
catch (InterruptedException e)
{
throw new RuntimeException(e);
}
}
}

public void paint(Graphics g){
g.fillRect(i,80,70,40);
g.drawImage(im,i,80,this);
}
}
Gzd2003 2008-01-04
  • 打赏
  • 举报
回复
以上程序执行对应的test.html之后没有任何反应。
test.html的内容如下:
<applet code="juxing.class" width="500" height="500"/>

test.html和juxing.class位于同一个目录下。

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧