2006-2007学年第一学期期末考试试题(A卷)(2)
4.根据下面给出的html文件,完成后面的程序:
<html>
<applet code = FontPassDemo width = 400? height = 200>
<param name=font ?value="Helvetica" >
<param name=size ?value="28" >
</applet>
</html>
?
import java.awt.*;
import java.applet.*;
public class _____①_______ extends Applet {
?String quote;
?Font f;
?public void init() {
? quote=" Happiness is an attitude.";
? String fontname=getParameter(___②_______);
? int fontsize=Integer.parseInt(getParameter(_____③_________);
? f=new Font(fontname,Font.ITALIC,fontsize);
?}
?public void paint(Graphics g) {
??? g.setFont(f);
??? g.drawString(quote,20,100);
?}
}
?
5.下面程序从mytest.txt文件中读取字符,将读到的文字列在TextArea里面。
import java.awt.*;
import java.io.*;
public class BufferedReaderTest extends Frame {
? public static void main(String args[]) {
? String str;
? ________①_________? Test test=new BufferedReaderTest();
? TextArea ta=new TextArea();
? try {?? //建立一个BufferedReader流读取文件
?????????? BufferedReader breader=new BufferedReader(_______②_________);
?????????? while(true) {
?????????? ???????? str=breader.readLine();???? //读取一行文字
????????? ?????????? if(str==null)???? //读到文件结尾
??????????? ????????????? break;
????????? ?????????? ta.append(str+"\n");???? //将读到的文字列在TextArea里面
?????? ???????? }
? }
? catch(_____③________ e) {???? //捕获是否为文件未找到异常???
? }
? test.add(ta,BorderLayout.CENTER);
? test.setSize(500,200);
? test.setVisible(true);
? }
}
?