华南俳烁实业有限公司

自考

各地資訊
當(dāng)前位置:考試網(wǎng) >> 自學(xué)考試 >> 自考真題 >> 工學(xué)類 >> Java 語言程序設(shè)計(一) >> 文章內(nèi)容

排行熱點

全國2014年4月高等教育自學(xué)考試Java語言程序設(shè)計(一)試題_第4頁

來源:考試網(wǎng) [ 2014年7月7日 ] 【大 中 小】

31.某個緩沖式輸出的示意程序的界面有一個文本框fileOut和一個文本區(qū)text,程序運 行時,先在文本區(qū)中輸入要存入文件的內(nèi)容,接著在文本框中輸入文件名并回車, 則程序?qū)⑽谋緟^(qū)中的內(nèi)容保存到指定的文件中。以下是該程序中相應(yīng)文本框文件名 的輸入事件的方法。

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.閱讀下列程序,請寫出該程序的輸出結(jié)果。

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.閱讀下列程序,請寫出調(diào)用Test33(4)的輸出結(jié)果。

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,在文本區(qū)中會顯示多少行整數(shù),各行有幾個數(shù)?

(2)如果將程序的第一行刪除,程序中標(biāo)號①~⑨語句中哪些會出現(xiàn)錯誤?

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)程序運行時,呈現(xiàn)的界面中菜單條有哪些菜單?

(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[][]={{"體育","跑步","打籃球","打乒乓"},

{"娛樂","唱歌","跳舞"},

{"學(xué)習(xí)","數(shù)學(xué)","語文"}};

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

window.setVisible(true);

}

}

責(zé)編:wuhuirong
潍坊市| 阳谷县| 龙游县| 上林县| 广水市| 全州县| 益阳市| 上犹县| 翁牛特旗| 玉屏| 定日县| 南宁市| 石林| 富阳市| 湛江市| 陵水| 渭南市| 拜城县| 天津市| 伊川县| 平果县| 丰都县| 雅江县| 来宾市| 开封市| 肥西县| 翁牛特旗| 通辽市| 韩城市| 崇仁县| 元氏县| 社旗县| 平安县| 海宁市| 甘肃省| 松江区| 东兰县| 临夏县| 苗栗县| 长阳| 天祝|