日新月异
5
公司 :杭州神话信息技术有限公司
部门 :运营中心设计部
岗位 :UI视觉设计
8
关注
15
粉丝
7030
微博
56
被赞
新浪微博
原创达人
友情链接:
找感兴趣的人
精彩内容
热门应用
关于我们
手机玩微博
注意:不改动程序的结构,不得增行或删行。
程序的执行结果为:
import java.awt.*;
import java.applet.*;
/*
<applet code=XiaoQiu width=800 height=600>
</applet>
*/
public class XiaoQiu extends Applet implements Runnable
{
int currentX=0,currentY=0;
Thread m_Draw=null;
public void init()
{
m_Draw=new Thread (super);
}
public void paint(Graphics g)
{
g.setColor(Color.blue);
mycircle(g,getSize().width/2,getSize().height/2,currentX,currentY);
}
public void start()
{
m_Draw.start();
try
{
Thread.sleep(500);
}
catch(InterruptedException e){}
}
public void stop()
{
if(m_Draw.isAlive())
m_Draw. stop();
}
public void run()
{
try
{
while(true)
{
currentX++;
currentY++;
if(currentX>i00&&(currentY>100))
{
currentX=0;
currentY=0;
}
paint();
Thread.sleep(100);
}
}
catch(InterruptedException e){}
}
public void mycircle(Graphics g,int x,int y,int rx, int ry)
{
g.filloval(x-rx,y-ry,2*rx,2*ry);
}
}
ex3 9_3. html:
<html>
<head>
<title>A Simple Program</title>
</head>
<body>
<applet cede=" XiaoQiu.class" width=800 height=400>
</applet>
</body>
</html>
正确答案:m_Draw=new Thread(this) if (currentX>100 | | (currentY>100)) repaint();m_Draw=new Thread(this), if (currentX>100 | | (currentY>100)) repaint(); 解析:本题主要考查Java Applet程序的设计,Java语句的线程机制以及for循环语句。解答本题的关键是比较熟练的掌握Java Applet程序的设计,Java语句的线程机制以及for循环语句的有关知