以下程序中,当用户单击“移动”按钮以后,就可以使用方向键控制屏幕上句子的移动,单击“停止”按钮,则句子不再随着方向键移动。运行结果如下图所示
注意:请勿改动其他已有语句内容,仅在横线处填入适当语句。
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Example2_8 extends Applet implements KeyListener
{
public void keyTyped(KeyEvent e) {}
public void keyReleased(KeyEvent e) {}
Button button;
Button stopButton;
Label out;
int x,y;
public void _______ ()
{
button = new Button("移动");
button.addActionListener(new AddMoveListener(this));
stopButton = new Button("停止移动");
stopButton.addActionListener(new RemoveListener(this));
stopButton.setEnabled(false);
out = new nabel("按下按钮以后我可以随方向键移动");
add(button);
add(stopButton);
add (out);
}
public void start()
{
super, start ();
}
public void keyPressed(KeyEvent e)
{
x=out.getBounds().x;
y=out.getBounds().y;
if(e.getKeyCode()==KeyEvent.VK_UP)
{
y=y-2;
if(y<=0) y=0;
out. setLocation (x, y);
}
else if(e.getKeyCode()==KeyEvent.VK_DOWN)
{
y=y+2;
if (y>=300) y=300;
out. setLocation (x, y);
}
else if(e.getKeyCode()==KeyEvent.VK_LEFT)
{
x=x-2;
if(x<=0) x=0;
out. setLocation (x, y);
}
else if(e.getKeyCode()==KeyEvent.VK_RiGHT)
{
第1题:
在考生文件夹中有一个工程文件execise107.vbp及窗体文件execise107.frm。在名为 Form1的窗体上已经绘制出所有控件,如下图所示。在运行时,如果单击Move按钮,则窗体上的汽车图标每0.1秒向右移动一次(初始状态下不移动);如果单击Stop按钮,则停止移动。
要求:
(1)设置适当控件的适当属性,使得汽车图标每0.1秒向右移动一次,而初始状态下不移动。
(2)请去掉程序中的注释符“'”,把程序中的问号“?”改为正确的内容。
(3)为两个命令按钮编写适当的事件过程。最后以原文件名保存。
注意:
不得修改已经给出的程序。编写的事件过程中不能使用变量,每个事件过程中只能有一条语句。
第2题:
下面是关于字符界面基本输入输出的程序,请在程序的每条横线处填写一个语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
______________________
public class SimpleCharInOut{
public static void main(String args[]){
char c=" ";
System.out.println("Enter a character please: ");
try{
____________________//接受用户键盘输入的字符并保存在变量c中
}
catch(________________________e){}
System.out.println("You've entered character "+c);
}
}
第3题:
下面是打印输出所有和为10000的连续整数(如:1998,1999,2000,2001,2002)的程序,请在每条横线处填写适当语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
public class Sum10000{
public static void main(String args[ ]){
int i;
int j;
int k;
int sum;
for(i=1;i<=10000;______________){
sum=0;
j=i;
__________________;
while(sum<10000)
{
______________
if(sum==10000) {
for(k=i;k<=j;k++)
System.out.println(k+ "");
System.out.println("********");
}
}
}
}
第4题:
请完成下列Java程序。程序的输出结果:a=6,b=5。
注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。
程序运行结果如下:
public class ex38_2{
public static void main(String args[])
{
int a=5,b=6;
a=_________;
b=a-b;
a=_________;
System.out.println("a="+a+"\tb="+b);
}
}
第5题:
在名为Form1的窗体上绘制一个命令按钮,名为Crud1,标题为“移动按钮”,如下图所示。编写适当的事件过程,使得程序运行时,每单击命令按钮一次,该按钮向右移动100。
注意:
程序中不得使用变量,事件过程中只能写一条语句;文件必须存放在考生文件夹中,工程文件名为execise54.vbp,窗体文件名为execise54.frm。
第6题:
下面的程序是用do_while语句计算10的阶乘。请在程序的每条横线处填写一个语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
源程序文件代码清单如下:
public class DoWhileLoop
{
public static void main(________)
{
int n=10;
long result=1;
do
{
_______________
}
______________
System.out.println("10的阶乘为: "+result);
}
}
第7题:
下面的程序的功能是简单的进行键盘输入测试,请在程序的每条横线处填写一个语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
____________________
public class TestKeyBoardInPut
{public static void main(String[] args)
{String yourname=JOptionPane. ____________________ ("What is your name?");
System.out.println("Hello"+yourname);
____________________.exit(0);
}
}
第8题:
下面程序执行后,输出结果为:true请在程序的每条横线处填写一个语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
public class TestStringCompare{
{public static void main(String ____________________ args)
{char charl[]={'t','e','s','t'};
char char2[]={'t','e','s','t','1'};
String str1=new String(___________________);
String str2=new String(char2,0,4);
System.out.println(__________________________);
}
}
第9题:
下面的程序是用do-while语句计算10的阶乘。请在程序的每条横线处填写1个语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容;仅在横线处填入适当的语句。
源程序文件代码清单如下:
public class DoWhileLoop
{
public static void main(______)
{
int n=10;
long result=1;
do
{
_____;
}
_____;
System.out.println("10的阶乘为:"+result);
}
}