1、计算机二级 JAVA-162 (1)及答案解析(总分:100.00,做题时间:90 分钟)一、简单应用题(总题数:3,分数:100.00)1.本程序是一个 Applet,页面中有 10 个按钮,名称从“0”“9”,用鼠标任意单击其中一个按钮后,通过键盘上的上下左右键可以控制按钮在窗口上移动,如图所示。 (分数:30.00)_2.本程序中,主窗口中有一个按钮,按钮的长和宽每 200 毫秒增加 1,当达到 100 时又恢复原来大小重新进行增加,如图所示。 import java.awt.*; import java.awt.event.*; public class exam_94 public
2、static void main(String args) Mywin win=new Mywin(); class Mywin extends Frame _ Button b=new Button(“按钮“);int x=5; Thread bird=null; Mywin() setBounds(100,100,400,400);setLayout(new FlowLayout(); setTitle(“exam_94“); setVisible(true); add(b);b.setBackground(Color.green); addWindowListener(new Windo
3、wAdapter() public void windowClosing(WindowEvent e) System.exit(0); ); bird=new Thread(this); bird.start(); public _ () while(true) x=x+1; if(x100) x=5; b.setBounds(40,40,x,x); try bird.sleep(200); catch(InterruptedException e) (分数:30.00)_3.本程序是一个 Applet,其功能是用户对文本框的输入,如果输入的是数字(09)或者是点(.),则接受并在文本框中显示
4、,否则不接受,如图所示。 (分数:40.00)_计算机二级 JAVA-162 (1)答案解析(总分:100.00,做题时间:90 分钟)一、简单应用题(总题数:3,分数:100.00)1.本程序是一个 Applet,页面中有 10 个按钮,名称从“0”“9”,用鼠标任意单击其中一个按钮后,通过键盘上的上下左右键可以控制按钮在窗口上移动,如图所示。 (分数:30.00)_正确答案:()解析:第 1 处:implements KeyListener 第 2 处:keyPressed(KeyEvent e)2.本程序中,主窗口中有一个按钮,按钮的长和宽每 200 毫秒增加 1,当达到 100 时又恢
5、复原来大小重新进行增加,如图所示。 import java.awt.*; import java.awt.event.*; public class exam_94 public static void main(String args) Mywin win=new Mywin(); class Mywin extends Frame _ Button b=new Button(“按钮“);int x=5; Thread bird=null; Mywin() setBounds(100,100,400,400);setLayout(new FlowLayout(); setTitle(“exa
6、m_94“); setVisible(true); add(b);b.setBackground(Color.green); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0); ); bird=new Thread(this); bird.start(); public _ () while(true) x=x+1; if(x100) x=5; b.setBounds(40,40,x,x); try bird.sleep(200); catch(InterruptedException e) (分数:30.00)_正确答案:()解析:第 1 处:implements Runnable 第 2 处:void run3.本程序是一个 Applet,其功能是用户对文本框的输入,如果输入的是数字(09)或者是点(.),则接受并在文本框中显示,否则不接受,如图所示。 (分数:40.00)_正确答案:()解析:第 1 处:extends PlainDocument 第 2 处:text.setDocument(document)