1、5.在以下Swing的类中,属于容器的是( )A.JApplet B.JButtonC.JTextArea D.JMenu6.在以下供选择的方法中,属于接口MouseMotionListener的方法是( )A.mouseReleased() B.mouseEntered()C.mouseExited() D.mouseMoved()7.小程序要播放音频文件,可使用类( )A.Audio B.JAudioC.AudioClip D.JAudioClip8.以下是关于线程的叙述,正确的是( )A.多线程的使用可以提高设备的平行工作能力,但是使系统管理变得复杂B.同一个进程下的线程都有自己的状态、
2、专用数据段和独立的内存资源C.线程是能独立运行的程序D.进程的执行效率比线程的执行效率高9.在Java的类库中,包含实现输入/输出操作的包是( )A.java.util B.java.ioC.java.applet D.java.awt10.在编写访问数据库的Java程序时,ResultSet对象的作用是( )A.建立新数据库连接 B.用来表示与数据库的连接C.在指定的连接中处理SQL语句 D.存储查询结果二、填空题(本大题共10小题,每小题2分,共20分)请在每小题的空格中填上正确答案。错填、不填均无分。11.Java语言采用多种机制来保证可移植性,其中最主要的是_。12.程序包声明的格式是
3、_。13.当联编推迟至运行时间实现时,该联编过程称为_。14.使用默认字节字符对应表,将字符串转化为字节数组的方法是_。15.在Swing中,带有滚动条的面板的类名是_。16.组合框(JComboBox)是_的组合。17.在某个组件中绘图,一般应该为这个组件所属的子类重写_方法。18.多线程互斥使用_的程序段,在操作系统中称为临界段。19.在Java语言中,文件随机访问可以利用_类实现。20.Java程序可以用纯Java的_驱动程序,实现与数据库连接。三、简答题(本大题共6小题,每小题3分,共18分)21.请使用for循环语句计算S=1+的值。22.请写出Applet类中init()方法的功能
4、。23.请写出空布局安置组件的两个步骤。24.在Swing中,对话框有几种?并请写出它们的主要区别。25.请写出用Runnable接口实现多线程的主要工作。26.请写出用InetAddress类,获取网址为“”的IP地址的Java语句。四、程序填空题(本大题共5小题,每空2分,共20分)27.方法booleanisPrime(intn)的功能是判断正整数n(n1)是否为质数。static boolean isPrime(intn) int i。 if(n=2)return true。 if(n%2=0)return false。 for(i=3。i*i=n。i+=2) if(_) break。
5、 if(_) return true。 return false。28.某小应用程序窗口中有一个文本框,一个8行10列的文本区以及一个按钮,点击这个按钮时,在文本框中输入的内容会追加到文本区中。 import java.applet.*。 import javax.swing.*。 import java,awt.event.*。 public class TextAPP extends Applet implements ActionListener JTextField input。 JTextArea display。 JButton append。 public void init()
6、 input = new JTextField(10)。 display = new 。 append = new JButton(追加)。 add(input)。 add(display)。 add(append)。 input.requestFocus()。 display.setLineWrap(true)。 append.addActionListener(this)。 public void actionPerformed(ActionEvent e), display.(input.getText() + 29.某小应用程序有一个由3个单选按钮组成的颜色选择组,当选中某种颜色时,窗
7、口的背景颜色将作相应的变化。这里给出的是窗口子类My Window的定义的框架以及其构造函数的定义。class MyWindow extends JFrame implements MyWindow(String s) super(s)。 Container con = this.getContentPane()。 con.setLayout(new GridLayout(3,2)。 this.setLocation(100, 100)。 this.setSize(400, 400)。 panel 1 = new Panel l ()。 label l = new JLabel(改变前景颜色,
8、JLabel.CENTER)。 con.add(label 1 )。 con.。 panel 1 .box 1 .addltemListener(this)。 panel 1 .box 2.addItemListener(this)。 panel 1 .box 3.addItemListener(this)。 this. setVisible (true)。 this.pack()。30.某小应用程序的界面有两个按钮,点击“画圆”按钮,程序在窗口画一个圆,点击“画矩形”按钮,程序在窗口画一个矩形。import java.applet.*。 import java.awt.*。import ja
9、va.awt.event.*。import javax.swing.*。public class Class l extends Applet implements ActionListener boolean c = false。 int r = 50,a = 50, b = 50。 JButton bl, b2。 public void init() setSize(200, 200)。 setBackground(Color.blue)。 b1 = new JButton(画 圆 b2 = new JButton(画矩形 b1.addActionListener(this)。 b2.ad
10、dActionListener(this)。 add(b1)。 add(b2)。 setVisible(true)。 public void (Graphics g) g.clearRect(70, 100, 130, 200)。 g.setColor(Color. red)。 if(c) g.drawRoundRect(70, 100, r, r, r, r)。 else g.drawRect(70, 100, a, b)。 public void update(Graphics g) paint(g)。 public void actionPerformed(ActionEvent e)
11、if(e.getSource()=b1) c = true。 else if(e.getSource()=b2) c = false。;31.某按钮的监视器方法actionPerformed()实现将文本区中的内容写入到文本文件myText.txt中。 public void actionPerformed(ActionEvent e) try int n = txtFld.getText().length()。 byte buffer=new byten。 buffer=txtFid.getText().getBytes()。 FileOutputStream wf=new (myText.
12、txt wf. write(buffer, 0,n)。 catch (IOException ioe) txtFld.setText(ioe.toString()。五、程序分析题(本大题共5小题,每小题4分,共20分)32.阅读下列程序,请写出该程序的输出结果。public class A int m = 5。 static int n = 3。 public static void main(String args) A obj 1 = new A()。 A obj2 = new A()。 objl.m *= 2。 objl.n *= 4。 obj2.m += 1。 obj2.n += 6。
13、 System.out.println(obj 1.m= + obj 1.m)。obj 1.n= + obj 1.n)。obj2.m= + obj2.m)。obj2.n= + obj2.n)。33.阅读下列程序,请写出该程序的输出结果。class Test33 static int merger(int a, int b, int c) int i = 0, j = 0, k = 0。 while(i a.length & j b.length) if(ai bj)ck+ = ai+。 else ck+ = bj+。 a.length) ck+ = ai+。 while(j b.length)
14、 ck+ = bj+。 return k。 int a = 3, 6, 9。 int b = 1, 2, 5。 int c = new int100。 int p = merger(a, b, c)。 for(int k = 0。 k p。 k+) System.out.print(ck+ (k p-1 ?:n)。34.阅读下列程序,请写出该程序的功能。import java.awt.*。 import java.awt.event.*。public class Class l extends Applet implements ActionListener JTextField Text I
15、 =new JTextField(5)。 JTextField Text2=new JTextField(5)。 JTextField Text3=new JTextField(5)。 JLabel Label 1 =new JLabel(Please input three numbers: JLabel Label2=new JLabel( JButton but=new JButton(Start! setLayout(new GridLayout(6,1)。 add (Label 1)。 add (Textl)。 add (Text2)。 add (Text3)。 add (but)。
16、 add (Label2)。 Label2.setFont(new Font (Courier, 1, 20)。 but.addActionListener(this)。 int a,b,c。 a=Integer.parseInt(Text 1.getText()。 b=Integer.parselnt(Text2.getText()。 c=Integer.parselnt(Text3.getText()。 if (a + b c | b + c a | c + a b) Label2 .setForeground (Color. red )。Courier , 1, 24)。 Label2.
17、setText(No. else Label2.setForeground(Color.blue)。, 2, 24)。 Yes.35.阅读下列程序,请写出该程序的功能。class MyScrollBar extends JScrollBar public MyScrollBar(int init, int len, int low, int high) super(JScrollBar.HORIZONTAL, init, len, low, high)。 public Dimension getPreferredSize() return new Dimension(125, 20)。clas
18、s MyWindow extends JFrame implements AdjustmentListener private JTextField text。 MyWindow(String s) MyScrollBar tempBar = new MyScrollBar(l0, 10, 0, 255)。 con.setLayout(new GridLayout(2,1)。 this.setSize(250, 100)。 tempBar.addA djustmentListener(this)。 text= new JTextField(移动滚动条的滑块,20)。 con.add(text)
19、。 con.add(tempBar)。 this.setVisible(true)。public void adjustmentValueChanged(AdjustmentEvent e) MyScrollBar myBar=(MyScrO11Bar)e.getAdjustable(); text.setText(选择的值是:+myBar.getValue();public class Test35 public static void main(String args) new MyWindow(滚动条示意程序36.阅读下列程序,请写出该程序的功能。import java util.*。c
20、lass MyThread extends Thread int pauseTime。 String name。 public MyThread (int x, String n) pauseTime = x。 name = n。 public void run() for(int i = 1。i = 4。 i+) System.out.println(name + +new Date(System.currentTimeMillis()。 Thread.sleep(pauseTime)。 catch(Exception e) public class Test36 static public
21、 void main(String args) MyThread thread1 = new MyThread (1000,Fast Thread thread 1 .start()。 MyThread thread2 = new MyThread (3000,Slow Thread thread2.start()。六、程序设计题(本大题共2小题,每小题6分,共12分)37.请编写方法int countNum(String str),该方法的功能是统计已知字符串str中数字的个数。例如,countNum(A42B83C2D)的返回值是5。38.一个小应用程序,界面如下图所示,其功能为实现摄氏温
22、度和华氏温度的相互转换。以下是程序的大部分,请编写其中的监视器方法。 注:华氏温度(F)=摄氏温度(C)95+32public class test38 extends Applet implementsActionListener JTextField textl, text2。 JButton c2f, f2c。 text l = new JTextField(5)。 text2 = new JTextField(5)。c2f=new JButton(摄氏转换为华氏);f2c=new JButton(华氏转换为摄氏add(text 1);add(text2); add(c2f);add(f
23、2c);text1.requestFocus();c2f.addActionListener(this);f2c.addActionListener(this);public void actionPerformed(ActionEvent e) /请在以下位置编写代码版权申明本文部分内容,包括文字、图片、以及设计等在网上搜集整理。版权为潘宏亮个人所有This article includes some parts, including text, pictures, and design. Copyright is Pan Hongliangs personal ownership.用户可将
24、本文的内容或服务用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯本网站及相关权利人的合法权利。除此以外,将本文任何内容或服务用于其他用途时,须征得本人及相关权利人的书面许可,并支付报酬。Users may use the contents or services of this article for personal study, research or appreciation, and other non-commercial or non-profit purposes, but at the same time, they
25、shall abide by the provisions of copyright law and other relevant laws, and shall not infringe upon the legitimate rights of this website and its relevant obligees. In addition, when any content or service of this article is used for other purposes, written permission and remuneration shall be obtai
26、ned from the person concerned and the relevant obligee.转载或引用本文内容必须是以新闻性或资料性公共免费信息为使用目的的合理、善意引用,不得对本文内容原意进行曲解、修改,并自负版权等法律责任。Reproduction or quotation of the content of this article must be reasonable and good-faith citation for the use of news or informative public free information. It shall not misinterpret or modify the original intention of the content of this article, and shall bear legal liability
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1