为什么这个JAVA小程序不能实现小程序查看器窗口的不断移动呢?
packagexcx;importjava.awt.*;importjava.applet.*;importjava.net.*;publicclassMove4exte...
package xcx;
import java.awt.*;
import java.applet.*;
import java.net.*;
public class Move4 extends Applet implements Runnable
{
URL url;
int x;
int y;
public void init()
{
try
{
url=new URL("file:/E:/workspace/song.mid");
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
resize(400,300);
}
public void start()
{
Thread th=new Thread(this);
th.start();
play(url);
}
public void move()
{
x=(int)(Math.random()*500);
y=(int)(Math.random()*300);
setLocation(x,y);
}
public void run()
{
try
{
for(int i=0;i<20;i++)
{
move();
Thread.sleep(100);
}
}
catch(Exception e){}
}
} 展开
import java.awt.*;
import java.applet.*;
import java.net.*;
public class Move4 extends Applet implements Runnable
{
URL url;
int x;
int y;
public void init()
{
try
{
url=new URL("file:/E:/workspace/song.mid");
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
resize(400,300);
}
public void start()
{
Thread th=new Thread(this);
th.start();
play(url);
}
public void move()
{
x=(int)(Math.random()*500);
y=(int)(Math.random()*300);
setLocation(x,y);
}
public void run()
{
try
{
for(int i=0;i<20;i++)
{
move();
Thread.sleep(100);
}
}
catch(Exception e){}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询