| 四、程序填空題(本大題共5小題,每空2分,共20分) 27.方法void moveOddForword(int a[ ])的功能是將數(shù)組中的所有奇數(shù)移到所有偶數(shù)之前。 void moveOddForword(int a[]){ for(int i=0, odd=0;________;i++) if(________){ int t=a[i];a[i]=a[odd];a[odd]=t;odd++; } } 28.以下程序創(chuàng)建了一個窗口,然后在窗口內顯示″Hello,World! ″。 import javax.swing.*; import java.awt*; public class HelloWorld { public static void main(String[ ]ares) { TextFrame frame=new TextFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame. ________; } } class TextFrame extends JFrame { public TextFrame() { . setTitle(″HelloWorld″); setSize(WIDTH,HEIGHT); TextPanel panel=new TextPanel(); Container contentPane=getContentPane(); contentPane.add(panel); } public static final int WIDTH=300; public static final int HEIGHT= 200; } class TextPanel extends JPanel { public void paintComponent(Graphics g) { super. ________; g.drawString(″Hello,World! ″,x,y); } public int x=100; public int y=100; } 29.以下是子窗口中設置一個菜單條類的定義。類的構造方法根據(jù)指定的窗口名稱和菜單表設置菜單條,菜單和菜單項,當選中某個菜單項時,在文本框中顯示相應菜單項被選中的信息。 class MenuWindow extends JFrame implements ActionListener { public static JTextField text; public 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<menuList[i].1ength;j++){ JMenultem anltem=new JMenultem(menuList[i][j]); anltem.setActionCommand(menuList[i][j]); anltem.________;menu.add(anltem); } menubar.__________; } text=new JTextField();setJMenuBar(menubar); con.add(text,BorderLayout.SOUTH); } public void actionPerformed(ActionEvent e){ text.setText(e.getActionCommand()+″菜單項被選中! ″); } } public class Test29 extends Applet { MenuWindow window; String menuList[][]={{″體育″,″跑步″,″打藍球″,″打乒乓″}, {″娛樂″,″唱歌″,″跳舞″}}; public void init() { window=new MenuWindow(″體育娛樂之窗″,menuList); window.setVisible(true); } } 30.以下是一個用鼠標自由作畫的小應用程序。最簡單的方法是根據(jù)鼠標所在位置畫點,跟隨鼠標的移動,不斷畫圓點,就能實現(xiàn)用鼠標作畫。 import java.awt.*; import java.awt.event.*; public class Test30 extends java.applet.Applet implements MouseMotionListener { Color color;int lineSize=2: int x=-1,y=-l; public void init(){ setLocation(30,20); setSize(300,300); setBackground(Color.green);addMouseMotionListener(this); } public void paint(Graphics g){ if(x!=-1&&y!=-1) { g.setColor(color);g.fillOval(x,y,1ineSize,lineSize); } } public void mouseMoved(MouseEvent e){} public void mouseDragged(MouseEvent e){ x=e.getX();y=e.getY();_________; } public void ________ (Graphics g){ paint(g);} } 31.以下定義的類ShareData用于管理多個線程共享數(shù)據(jù)data。一個線程生成data,另一個線程使用data。約定,新生成的data只有被另一個線程使用后,才能生成下一個data。反之,一個data被使用后,也不能再繼續(xù)使用。所以,生成和使用data的線程之間需要互斥和同步。以下是管理上述使用方式的類,類內有要管理的共享數(shù)據(jù),以及對共享數(shù)據(jù)的存操作putData()和取操作getData()。 class ShareData{ int data;∥共享數(shù)據(jù) boolean newData=false;∥有最近新生成data的標志 synchronized int getData(){ while(!newData){ try{ _________; } catch(InterruptedExceptipn e){ System.out.println(″因錯誤,而中斷!″); } } newData=false; notify();return data; } synchronized void putData(int n){ while(newData){ try{wait(); }catch(InterruptedException e){ System.out.println(″因錯誤,而中斷! ″); } } data=n; __________; notify(); return; } }
五、程序分析題(本大題共5小題,每小題4分,共20分) 六、程序設計題(本大題共2小題,每小題6分,共1 2分) |
| 熱門資料下載: |
| < |
| 自考最新熱貼: |
【責任編輯:育路編輯 糾錯】 |
|
閱讀下一篇:浙江:2010年1月高等教育自學考試 |
|
|
| 【育路網(wǎng)版權與免責聲明】 | |
| ① 凡本網(wǎng)注明稿件來源為"原創(chuàng)"的所有文字、圖片和音視頻稿件,版權均屬本網(wǎng)所有。任何媒體、網(wǎng)站或個人轉載、鏈接、轉貼或以其他方式復制發(fā)表時必須注明"稿件來源:育路網(wǎng)",違者本網(wǎng)將依法追究責任; | |
| ② 本網(wǎng)部分稿件來源于網(wǎng)絡,任何單位或個人認為育路網(wǎng)發(fā)布的內容可能涉嫌侵犯其合法權益,應該及時向育路網(wǎng)書面反饋,并提供身份證明、權屬證明及詳細侵權情況證明,育路網(wǎng)在收到上述法律文件后,將會盡快移除被控侵權內容。 | |
熱點專題 |