首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

2006-2007学年首先学期期末考试试题(B卷)(2)

2012-12-20 
2006-2007学年第一学期期末考试试题(B卷)(2)3.下面程序是响应按钮myButton单击事件的程序片断,其中类MyLis

2006-2007学年第一学期期末考试试题(B卷)(2)

3.下面程序是响应按钮myButton单击事件的程序片断,其中类MyListener为事件类,给出横线处的代码,完成程序功能。

public class MyEventTest extends Panel {

?Button myButton = new? Button("蓝色");

?.? .? . // 创建面板或其他 GUI 组件

??? MyListener? myAction = new? MyListener();

??? MyButton._______①__________(myAction);

??? private class MyListener implements _______②_________ {

?? ???????? public MyListener() {?

???? . . . // 初始化?

?? }

?? public void _________③___________(ActionEvent event) {//事件处理方法

??? . . .//需要为事件进行的操作

?? }

?}

}

?

?

4.根据下面图形的要求,完成Applet小程序:


2006-2007学年首先学期期末考试试题(B卷)(2)
??

1)HTML文件

<html>

<applet code=___①_____ width=200 height=200>

</applet>

</html>

2)JAVA文件

import java.awt.*;

import java.applet.*;

public class Firstapplet ____②______ {

? String s;

? public void init() {

?? s= "你好,世界!";

? }

? public void paint(Graphics g){

???? ______③________(s, 70, 80);

? }

}

?

5.下面程序实现了文件拷贝功能,从file1.txt 把文字复制到file2.txt。

?

import java.io.*;

public class filestream {?

public static void main(String args[]){

try{??

??????????? File inFile=_____①_______;

??????????? File outFile=____②_________;

??? ??????? FileInputStream fis=new? FileInputStream(inFile);

??? ??????? FileOutputStream fos=new FileOutputStream(outFile);

??? ??????? int c;?

?????? ???? while((c=fis.read())!=-1)?

______③__.write(c);

??????? ??? fis.close();

fos.close();??

}

??? ?? catch(FileNotFoundException e) {

?????????? System.out.println("FileStreamsTest: "+e);

}

??? ?? catch(IOException e) {

??????????? System.err.println("FileStreamsTest: "+e);}}

}

?

热点排行