题目
下面是一个Applet小程序,其功能为:以坐标(10,20)为起点,画一条长为80个像素点的绿色直线,请在横线处填写一条语句,使程序的完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
______________________
import java.awt.*;
public class test_drawline extends Applet
{
public void paint(_______________)
{
g.setColor(Color.green);
_____________________
}
}
第1题
下面是一个递归Java程序,其功能为 ()long Factorial(int n){ if(1==n){ return 1; } else return n*Factorial(n-1);}
A.求1-n的和
B.求2到n的和
C.求n的阶乘
D.求2-n的积
第2题
下面是一个递归Java程序,其功能为 () long Factorial(int n){ if(1==n){ return 1; } else return n * Factorial (n-1); }
A.求1-n的和
B.求2到n的和
C.求n的阶乘
D.求2-n的积
第3题
A.求1至n的累加和
B.求n的阶乘
C.求n-1的阶乘
D.函数固定结果为1
第4题
A.求1至n的累加和
B.求n的阶乘
C.求n-1的阶乘
D.函数固定结果为1
第5题
A.求1至n的累加和
B.求n的阶乘
C.求n-1的阶乘
D.函数固定结果为1
第6题
A.求1至n的累加和
B.求n的阶乘
C.求n-1的阶乘
D.函数固定结果为1
第7题
A.求1至n的累加和
B.求n的阶乘
C.求n-1的阶乘
D.函数固定结果为1
第8题
下面的Applet程序,其功能为画一个正方形,大小140*140,其背景色为蓝色(其填充色为pink色,各边离Applet的边为10像素)和一个在填充的正方形中自右上到左下来回移动的小球(半径15)。请改正程序中的错误(有下划线的语句),使程序执行后,能得到预期的结果。
注意:不改动程序的结构,不得增行或删行。程序的执行结果为:
import java.awt.*;
import java.applet.*;
/*
<applet code=BallAnim width=800 height=600>
</applet>
*/
//画一个正方形和一个移动的球,实现了Runnable接口。
public class BallAnim extends Applet implements Runnable
{
Thread animThread;
int ballX=100;//球的x坐标
int bally;10;//球的Y坐标
int ballDirection=0;//球移动的方向标志:0表示从上向下移动,1表示从下向上移动
public void init()
{
super.setBackground(Color.blue);
}
public void start()
{
if (animThread !=null)
{
animThread = new Thread(this);
animThread.start();
}
}
public void stop()
{
animThread.stop();
animThread = null;
}
// 实现Runnable接
public void run()
{
Thread.currentThread().setPriority(Thread. NORM_PRIORITY);//设置线呈优先级
NORM_PRIORITY
while (true)
{
moveBall();
try
{
Thread.sleep(100); // 休眠0.1秒
}
catch (Exception sleepProblem)
{
// This applet ignores any exceptions if it has a problem sleeping.
// Maybe it should take Sominex
}
}
}
private void moveBall ()
{
// 球对角运动
if (ballDirection == 0)
{
ballX-=2; / / 如果球从左向右运动,球的X坐标减少2
ballY+=2; / / 如果球从上向下运动,球的Y坐标增加2
if (ballY > 100)//球的Y坐标增加到100, 改变球的运动方向
{
ballDirection = 1;
ballX = 10;
ballY=100;
}
}
else
{
ballX+=2; //如果球从右向左运动,球的X坐标增加2
ballY-=2;//如果球从下向上运动,球的Y坐标减少2
if (bally <= 10)//球的X坐标减少到10,改变球的运动方向
{
ballDirection = 0;
ballX = 100;
ballY=10;
}
}
paint();
}
public void paint(Graphics g)
{
g.setColor(Color.pink);
g.fillRect(10, 10, 120, 120);
g.setColor(Color.green);
g.fillOval(ballX,ballY, 30, 30);
}
}
ex40_3, html:
<html>
<head>
<title> ex40_3</title>
</head>
<body>
<applet code=" BallAnim.class" width=800 height=400>
</applet> </body> </html>
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!