国产在线精品一级A片-国产另类欧美-国产精品va在线观看一-我要找美国一级片黄色|www.zheinei.com

Java語言程序設(shè)計試題及答案六

時間:2017-04-20 14:51:32 java試題 我要投稿

Java語言程序設(shè)計試題及答案(六)

  Java語言程序設(shè)計想要在考試中脫穎而出也不是不行的哦。為此陽光網(wǎng)小編為大家推薦了Java語言程序設(shè)計測試題和答案,希望能幫到大家。

Java語言程序設(shè)計試題及答案(六)

  Java語言程序設(shè)計測試題

  一、單項選擇題(本大題共10小題,每小題1分,共10分) 在每小題列出的四個備選項中只有一個是符合題目要求的,請將其代碼填寫在題后的括號內(nèi)。錯選、多選或未選均無分。

  1. 在編寫Java applet程序時,若需要對發(fā)生事件作出響應(yīng)和處理,一般需要在程序的開頭寫上的語句是() (1分)

  A:import java.awt.*;

  B:import java.applet.*;

  C:import java.io.*;

  D:import java.awt.event.*;

  2. Java語言約定,顯示屏上一個長方形區(qū)域為程序繪圖區(qū)域,坐標(biāo)原點(0,0)位于整個區(qū)域的() (1分)

  A:中心

  B:左上角

  C:右上角

  D:自由設(shè)定

  3. 在Java程序中定義一個類,類中有一個沒有訪問權(quán)限修飾的方法,則此方法() (1分)

  A:訪問權(quán)限默認為是public

  B:訪問權(quán)限默認為是private

  C:訪問權(quán)限默認為是protected

  D:以上都不是

  4. 在Java 中,能實現(xiàn)多重繼承效果的方式是() (1分)

  A:內(nèi)部類

  B:適配器

  C:接口

  D:同步

  5. 在Java語言中,密碼框組件和設(shè)置密碼框的回顯字符為“*”的方法分別是() (1分)

  A:JPassWordField和setEchoChar(?*?)

  B:JPasswordField和setEchoChar(?*?)

  C:JPassWordField和setEchochar(?*?)

  D:JPasswordField和setEchochar(?*?)

  6. 使用數(shù)據(jù)庫的SQL命令實現(xiàn)數(shù)據(jù)庫的更新,應(yīng)利用Statement對象的方法() (1分)

  A:update()

  B:insert()

  C:executeUpdate()

  D:delete()

  7. 以下程序代碼的輸出結(jié)果是()

  short i=10,j,k=20;

  j=k+i++;

  System.out.print(j); (1分)

  A:30

  B:31

  C:出錯

  D:11

  8. 在Java語言中,移去按鈕對象監(jiān)視器的方法是() (1分)

  A:removeListener(ActionListener e)

  B:setRemoveEnable(ActionListener e)

  C:removeActionListener(ActionListener e)

  D:addActionListener(ActionListener e)

  9. 下列有關(guān)事件監(jiān)視器的說法正確的是() (1分)

  A:一個組件上不可以注冊多個事件監(jiān)視器

  B:一個事件監(jiān)視器可以被注冊到多個組件上

  C:一個組件上注冊多個事件監(jiān)視器會發(fā)生沖突,不會起作用

  D:一個組件上注冊多個事件監(jiān)視器,只有最后一個事件監(jiān)視器會起作用

  10. 菜單的事件源是用鼠標(biāo)點擊某個菜單項,ActionListener,要實現(xiàn)的接口方法是actionPerformed(ActionEvent e),獲得事件源的方法是

  getSource(),處理該事件的接口是() (1分)

  A:ActionListener

  B:actionPerformed

  C:getSource

  D:ItemListener

  二、填空題(本大題共10小題,每小題2分,共20分)請在每小題的空格中填上正確答案。錯填、不填均無分。

  1. 當(dāng)把Java的繪圖模式設(shè)置為異或模式紅色,并對同一個圓用同一個顏色綠色繪制兩遍時,則此圓的繪制情況是:。 (2分)

  2. 流使用結(jié)束后,關(guān)閉流并且釋放與該流相關(guān)的資源,用方法。 (2分)

  3. 是一種特殊的方法,這種方法的名字與它的類名相同,并且不返回結(jié)果,也不寫上void關(guān)鍵字。 (2分)

  4. Java語言提供一個Graphics2D類,這個類定義了幾種方法用于添加或改變圖形的狀態(tài)屬性,其中屬性控制線條的寬度、筆形樣式、線段連接方式或

  短劃線圖案。 (2分)

  5. 在已有類的基礎(chǔ)上,擴充屬性或擴充與改寫某些方法,生成新的類,這個方式稱為。 (2分)

  6. 在Java語言,使用關(guān)鍵字定義臨界段,能對共享對象的操作上鎖。 (2分)

  7. 在Java程序中,如果有package語句,則此語句必須出現(xiàn)在源程序文件的。 (2分)

  8. 采用布局的容器中多個組件擁有同一個顯示空間,某一時刻只能顯示一個組件。 (2分)

  9. 在Java語言中,邏輯右移運算符是。 (2分)

  10. 在Java語言中,有了SQL語句對象sql后,根據(jù)“讀取學(xué)生成績表st中的所有記錄并存于rs對象中”,定義rs對象的代碼是。 (2分)

  三、程序填空題(本大題共5小題,每空2分,共20分)

  1. 以下程序使字符串“文字的特殊輸出效果演示”中的所有文字每隔300毫秒顯示一個。

  public class Class3101

  {

  public static void main(String[] args)

  {

  String s="文字的特殊輸出效果演示";

  for(int i=0;i

  {

  System.out.print(s.substring(i,i+1));

  try{;}

  catch(){}

  }

  }

  } (2分)

  2. 下面小應(yīng)用程序通過快速顯示一組圖片(1.jpg~9.jpg)造成顯示動畫的效果。

  import java.awt.*;

  import java.applet.*;

  public class Class3002 extends Applet implements Runnable

  {

  final int number=9;

  int count=1;

  Image[]pic=new Image[number];

  Thread myThread;

  public void init()

  {

  setSize(300,200);

  for(int i=1;i<=number;i++)

  pic[i-1]=;

  }

  public void start()

  {

  myThread=new Thread(this);

  myThread.start();

  }

  public void stop(){myThread=null;}

  public void run()

  {

  while(true)

  {

  repaint();

  count=(count+1)%number;

  try{myThread.sleep(1000);}

  catch(InterruptedException e){}

  }

  }

  public void paint(Graphics g)

  {

  if(pic[count]!=null)

  g.(pic[count],10,10,200,200,this);

  }

  } (2分)

  3. 下面的程序在屏幕上顯示一個紅色窗口,窗口的左上角坐標(biāo)為(100,200),寬為300像素,高為400像素。

  import java.awt.*;

  import javax.swing.*;

  public class Class2803

  {

  public static void main(String[] args)

  {

  JFrame myWin=new JFrame("Class2803");

  myWin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//關(guān)閉窗口時,整個應(yīng)用程序關(guān)閉。若省略,關(guān)閉窗口時程序不終止,相當(dāng)于setVisible

  (false)

  myWin.;

  Container con=myWin.getContentPane();

  con.setBackground(Color.red);

  myWin.;

  }

  } (2分)

  4. 程序運行結(jié)果如下圖:上邊,左邊和右邊是三個按鈕,下邊是一個內(nèi)容為“Class2804”的文本框txt。

  import java.awt.*;

  import javax.swing.*;

  public class Class2804

  {

  public static void main(String[] args)

  {

  JFrame myWin=new JFrame("Class2804");

  myWin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  myWin.setBounds(100,200,300,200);

  Container con=myWin.getContentPane();

  con.setBackground(Color.red);

  con.setLayout(new BorderLayout());

  JButton button1=new JButton("左邊");

  JButton button2=new JButton("右邊");

  JButton button3=new JButton("上邊");

  con.add(button1,"West");

  con.add(button2,"East");

  con.add(button3,"North");

  myWin.setVisible(true);

  }

  } (2分)

  5. 下面程序運行后顯示一個窗口,在窗口中有一個按鈕和一個標(biāo)簽,單擊按鈕,標(biāo)簽中顯示按鈕被單擊的次數(shù),請完成程序。

  import java.awt.*;

  import javax.swing.*;

  import java.awt.event.*;

  class myFrame extends JFrame implements ActionListener

  {

  JButton button;

  JLabel label;

  myFrame(String s)

  {

  super(s);

  Container con=;

  setLayout(new FlowLayout());

  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  setSize(300,400);

  button=new JButton("OK");

  label=new JLabel("0");

  con.add(button); con.add(label);

  button.addActionListener(this);

  setVisible(true);

  }

  public void actionPerformed(ActionEvent e)

  {

  int n=;

  n++;

  label.setText(""+n);

  }

  }

  public class C2801

  {

  public static void main(String[] args)

  {

  new myFrame("我的窗口");

  }

  } (2分)

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

  1. 閱讀下列程序,畫出程序運行后初始界面并寫出程序功能。

  import java.applet.*;

  import java.awt.*;

  import java.awt.event.*;

  public class Class3603 extends Applet implements ActionListener

  {

  AudioClip clip;

  Button buttonPlay,buttonLoop,buttonStop;

  public void init()

  {

  clip=getAudioClip(getCodeBase(),"windowsXP關(guān)機.wav");

  buttonPlay=new Button("start");

  buttonLoop=new Button("loop");

  buttonStop=new Button("stop");

  buttonPlay.addActionListener(this);

  buttonStop.addActionListener(this);

  buttonLoop.addActionListener(this);

  setSize(300,100);

  add(buttonPlay);add(buttonLoop);add(buttonStop);

  }

  public void stop()

  {

  clip.stop();

  }

  public void actionPerformed(ActionEvent e)

  {

  if(e.getSource()==buttonPlay){clip.play();}

  else if(e.getSource()==buttonLoop){clip.loop();}

  if(e.getSource()==buttonStop){clip.stop();}

  }

  } (4分)

  2. 閱讀下列程序,寫出程序功能。

  import java.applet.*;

  import java.awt.*;

  import java.awt.event.*;

  public class C3601 extends Applet implements ActionListener

  {

  AudioClip clip;

  Button buttonPlay,buttonLoop,buttonStop;

  public void init()

  {

  clip=getAudioClip(getCodeBase(),"1.wav");

  buttonPlay=new Button("start");

  buttonLoop=new Button("loop");

  buttonStop=new Button("stop");

  buttonPlay.addActionListener(this);

  buttonStop.addActionListener(this);

  buttonLoop.addActionListener(this);

  setSize(300,100);

  add(buttonPlay);add(buttonLoop);add(buttonStop);

  }

  public void stop()

  {

  clip.stop();

  }

  public void actionPerformed(ActionEvent e)

  {

  if(e.getSource()==buttonPlay){clip.play();}

  else if(e.getSource()==buttonLoop){clip.loop();}

  if(e.getSource()==buttonStop){clip.stop();}

  }

  } (4分)

  3. 閱讀下列程序,寫出程序運行結(jié)果。

  public class C3302

  {

  public static void main(String[] args)

  {

  int [][]a={{1,2,3},{4,5,6}};

  System.out.println(a.length+","+a[0].length+","+a[1][1]);

  String[]s={"a","b"};

  f3302(s[0],s[1]);

  System.out.println(s[0]+","+s[1]);

  String s1="abc",s2="123";

  s1+="xyz";

  s2.concat("xyz");

  System.out.println(s1+","+s2);

  }

  static void f3302(String x,String y)

  {

  String z=x;x=y;y=z;

  }

  } (4分)

  4. 閱讀下列程序,寫出程序運行結(jié)果。

  import java.awt.event.*;

  import javax.swing.*;

  public class C3502 implements MouseMotionListener

  {

  JTextField text=new JTextField(30);

  C3502()

  {

  JFrame myWin=new JFrame("Ex0611");

  myWin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  myWin.setBounds(100,100,300,100);

  myWin.getContentPane().add(text,"North");

  myWin.addMouseMotionListener(this);

  myWin.setVisible(true);

  }

  public void mouseDragged(MouseEvent e)

  {

  int x=e.getX(),y=e.getY();

  text.setText("拖動鼠標(biāo),鼠標(biāo)坐標(biāo)為:"+x+","+y);

  }

  public void mouseMoved(MouseEvent e)

  {

  int x=e.getX(),y=e.getY();

  text.setText("移動鼠標(biāo),鼠標(biāo)坐標(biāo)為:"+x+","+y);

  }

  public static void main(String[] args)

  {

  new C3502();

  }

  } (4分)

  5. 閱讀下列程序,寫出程序功能。

  import java.applet.*;

  import java.awt.*;

  public class C3602 extends Applet implements Runnable

  {

  Thread myThread=null;

  public void start()

  {

  setSize(300,200);

  if(myThread==null)myThread=new Thread(this);

  myThread.start();

  }

  public void run()

  {

  while(true)

  {

  try{myThread.sleep(500);}

  catch(InterruptedException e){}

  repaint();

  }

  }

  public void paint(Graphics g)

  {

  double i=Math.random();

  if(i<0.33)g.setColor(Color.yellow);

  else if(i<0.66) g.setColor(Color.red);

  else g.setColor(Color.blue);

  int x=(int)(100*i);

  g.fillOval(x,x,x,x);

  }

  } (4分)

  五、程序設(shè)計題(本大題共2小題,每小題6分,共12分)

  1. 設(shè)計一個應(yīng)用程序窗口如下圖所示,單擊“加”或“減”按鈕,將前兩個文本框中的整數(shù)相加或相減后放入第三個文本框中。已給出部

  分代碼,請完成程序。

  import java.awt.*;

  import javax.swing.*;

  import java.awt.event.*;

  public class Class3801 implements ActionListener

  {

  JTextField text1,text2,text3;

  JButton addButton,subButton;

  public static void main(String[] args)

  {

  new Class3801();

  }

  public Class3801()

  {

  text1=new JTextField(10);

  text2=new JTextField(10);

  text3=new JTextField(10);

  addButton=new JButton("加");

  subButton=new JButton("減");

  JFrame myWin=new JFrame("Class3801");

  Container con=myWin.getContentPane();

  myWin.setSize(300,80);

  con.setLayout(new GridLayout(1,5));

  con.add(text1);con.add(text2);

  con.add(addButton);con.add(subButton);

  con.add(text3);

  addButton.addActionListener(this);

  subButton.addActionListener(this);

  myWin.setVisible(true);

  }

  public void actionPerformed(ActionEvent e)

  {

  //這里是你要編寫的代碼

  }

  } (6分)

  2. 創(chuàng)建一個有文本框和三個按鈕的程序。當(dāng)按下某個按鈕時,使不同的文字("Java","編程","不難學(xué)")顯示在文本框中。已經(jīng)給出部分代碼,請

  完成事件處理部分。

  import javax.swing.*;

  import java.awt.event.*;

  class MiYa1 extends JPanel

  {

  JButton button[]=new JButton[3];

  JTextField text;

  MiYa1()

  {

  for(int i=0;i<3;i++)

  {

  button[i]=new JButton("button0"+(i+1));

  add(button[i]);

  }

  text=new JTextField(10);

  text.setHorizontalAlignment(JTextField.CENTER);

  add(text);

  }

  }

  public class C3801 implements ActionListener

  {

  JFrame myWin;

  MiYa1 panel;

  C3801()

  {

  panel=new MiYa1();

  myWin=new JFrame("C3801");

  myWin.add(panel);

  myWin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  for(int i=0;i<3;i++)

  panel.button[i].addActionListener(this);

  myWin.pack();

  myWin.setVisible(true);

  }

  public static void main(String[] args)

  {

  new C3801();

  }

  public void actionPerformed(ActionEvent e)

  {

  //這里是你要編寫的代碼

  }

  } (6分)

  六、簡答題(本大題共6小題,每小題3分,共18分)

  1. 請解釋drawArc(int x,int y,int w,int h,int s,int a)方法的功能及參數(shù)含義。 (3分)

  2. CardLayout布局的容器可容納多個組件,但是多個組件擁有一個顯示空間。如何設(shè)置CardLayout布局及顯示某一組件? (3分)

  3. 請寫出RandomAccessFile類中read(byte b[],int s,int n)方法的功能及參數(shù)含義。 (3分)

  4. 要求創(chuàng)建一個URL對象url,使得url能夠訪問資源,請寫出一條語句。 (3分)

  5. 下列類的定義中有哪些錯誤?寫出錯誤原因或者進行改正。

  class C2202

  {

  int x;

  C2202(int x){this.x=x;}

  C2202(){C2202(10);}

  int f()

  {

  int a=1;

  x=a;

  }

  void g()

  {

  int y;

  y=a+x;

  }

  } (3分)

  6. 編寫訪問數(shù)據(jù)庫的Java程序需要幾個重要的類和接口,請任意寫出其中的三個。 (3分)

  >>>下一頁更多精彩“Java語言程序設(shè)計試題參考答案”