设为首页    加入收藏

自学考试省级导航

全国 A安徽 B北京 C重庆 F福建 G广东 广西 甘肃 贵州 H河南 河北 湖南 湖北 黑龙江 海南 J江苏 江西 吉林 L辽宁 N内蒙古 宁夏 Q青海 S山东 山西 陕西 四川 上海 T天津
     X新疆 西藏 Y云南 Z浙江 历年真题分类检索

全国2014年4月高等教育自学考试Java语言程序设计(一)真题(清晰word版)(四)
2015-02-09 20:07:20 来源:91考试网 作者:www.91exam.org 【

31.某个缓冲式输出的示意程序的界面有一个文本框fileOut和一个文本区text,程序运 行时,先在文本区中输入要存入文件的内容,接着在文本框中输入文件名并回车, 则程序将文本区中的内容保存到指定的文件中。以下是该程序中相应文本框文件名 的输入事件的方法。

public void actionPerformed(ActionEvent e){

if (e.getSource()==fileOut){

try{

out = new BufferedWriter(new ______ );

out.______ ;

out.flush(); out.close(); text.setText(null);

} catch (FileNotFoundException el){

System.out.print("文件没有找到!\n");

}catch (IOException exp){

System.out.print("文件读写出错!\n");

}

}

}

五、程序分析题(本大题共5小题,每小题4分,共20分)

32.阅读下列程序,请写出该程序的输出结果。

class Mother{

public voicl methodl(){

System.out.println("Call Mother's methodl()");

}

public void method2(){

System.out.println("Call Mother's method2()"); methodl();

}

}

class Girl extends Mother{

public void methodl(){

System.out.println("Call Girl's methodl()");

}

public static void main(String args[]){

Girl g= new Girl(); g.method2();

}

}

33.阅读下列程序,请写出调用Test33(4)的输出结果。

public static void Test33(int n){

int i,j,a[][]=new int[n][n];

for(i=0;i

if(i%2==0)

for(j=0;j

a[i][j]=j+1;

else for (j=n-l;j>=0;j--)

a[i][j]=n-j;

}

for(i=0;i

for(j=0;j

System.out.print("t"+ a[i][j]);

System.out.println();

}

}

34.阅读下列程序,请回答以下问题:

(1)在文本框中输入1 7,在文本区中会显示多少行整数,各行有几个数?

(2)如果将程序的第一行删除,程序中标号①~⑨语句中哪些会出现错误?

import java.awt.*;∥问题(2)所指要删除的行

import javax.swing.*;

import java.awt.event.*;

public class Test34 extends JFrame implements ActionListener{

JTextField textF; JTextArea textA;

Test34(){

Container con = getContentPane(); ∥①

con.setLayout(new BorderLayout()); ∥②

textF = new JTextField(10); ∥③

textF.addActionListener(this); ∥④

textA = new JTextArea(6, 10); ∥⑤

setSize(240, 200); ∥⑥

con.add(textF, "North"); ∥⑦

con.add(textA, "Center"); ∥⑧

setVisible(true); ∥⑨

public static void main(String[] args){

new Test34();

}

public voicl actionPerformed(ActionEvent e){

int n,d;

if(e.getSource()==textF){

n = Integer.parseInt(textF.getText());

for (int k=1;k<=n; k++){

d= (int) (Math.ranclom()*1000 % 1000);

textA.append(" "+d);

if(k%5==0)textA.append("");

}

}

}

}

35.阅读下列程序,请回答以下问题:

(1)程序运行时,呈现的界面中菜单条有哪些菜单?

(2)程序中带注释/*1*/的代码行的作用是什么?

import javax.swing.*;import java.awt.*;import java.awt.event.*;

class MenuWindow extends JFrame implements ActionListener{

JTextField text;

MenuWindow (String s,String menuList[][]){

setTitle(s);

Container con = this.getContentPane();

con.setLayout(new BorderLayout());

this.setLocation(100, 100); this.setSize(300, 100);

JMenuBar menubar=new JMenuBar();

for(int i=0;i< menuList.length; i++){

JMenu menu = new JMenu(menuList[i][0]);

for(int j=1;j

JMenuItem anItem=new JMlenuItem(menuList[i][j]);

/*1*/ anItem.setActionCommand(menuList[i][j]);

anItem.addActionListener(this); menu.add(anItem);

}

menubar.add(menu);

}

text = new JTextField(); setjMenuBar(menubar);

con.add(text,BorderLayout.SOUTH);

}

public void actionPerformed(ActionEvent e){

text.setText("<"+e.getActionCommand()+">菜单项被选中!");

}

}

public class Test35{

public static void main(String[] args){

MenuWindow window;

String menuList[][]={{"体育","跑步","打篮球","打乒乓"},

{"娱乐","唱歌","跳舞"},

{"学习","数学","语文"}};

window=new MenuWindow("菜单示例程序",menuList);

window.setVisible(true);

}

}

Tags:自学考试 历年真题
】【打印繁体】 【关闭】 【返回顶部
上一篇全国2012年10月自学考试Java语言.. 下一篇全国2013年10月自学考试《建筑经..

网站客服QQ: 960335752 - 14613519 - 48225117