我做了个简单的例子供参考(是用小黑框当图片):
Test.java的内容:import java.awt.*;
import java.applet.*;public class Test extends Applet
{
int x,y,ax,ay;
public void init()
{
x=200;
y=200;
ax=5;
ay=6;
}
public void paint(Graphics g)
{
while(x<=450 && y<=500)
{
g.clearRect(x-ax,y-ay,20,20);
g.fillRect(x,y,20,20);
try
{
Thread.sleep(50);
}
catch(InterruptedException e)
{}
x+=ax;
y+=ay;
}
}
}
Test.htm里的内容:
<BODY BGCOLOR="000000">
<APPLET
code = "Test.class"
width = "600"
height = "600"
>
</APPLET>
Test.java的内容:import java.awt.*;
import java.applet.*;public class Test extends Applet
{
int x,y,ax,ay;
public void init()
{
x=200;
y=200;
ax=5;
ay=6;
}
public void paint(Graphics g)
{
while(x<=450 && y<=500)
{
g.clearRect(x-ax,y-ay,20,20);
g.fillRect(x,y,20,20);
try
{
Thread.sleep(50);
}
catch(InterruptedException e)
{}
x+=ax;
y+=ay;
}
}
}
Test.htm里的内容:
<BODY BGCOLOR="000000">
<APPLET
code = "Test.class"
width = "600"
height = "600"
>
</APPLET>
setBounds呵呵,效果很差