,支持这个要求的类是__ Socket ____。
三、简答题(本大题共6小题,每小题3分,共18分)
21.请写出一段if语句,判断一个整数n是否为偶数。如果是偶数,输出“Yes.”;否则,输出“No.”。
If(n%2==0){System.out.println(“Yes”);}else{System.out.println(“No”);}
22.请写出接口定义的一般形式。(P59)
[Public] interface 接口名[extends 接口表 ]{ 接口体 }
23.请写出Java语言编写事件处理
程序的两种主要
方案。(P87)
(1)程序重设方法handleEvent( Event evt),(2)程序实现一些
系统设定的接口
24.设已经有Graphics2D对象g2d, 请用Java语句绘制一个矩形rect,其左上角坐标是(20,30),宽是120,高是30。
Rectangle2D rect=new Rectangle2D.Double(20,30,120,30)
G2d.draw(rect);
25.打开文件对话框时,还可以设置筛选条件,即指定文件的类型。请写出FileFilter类预设的两个方法。accept() getDescription()
26.请写出URLConnection类提供的三个
常用方法。
getOutputStream()
getInputStream()
connect()
四、程序填空题(本大题共5小题,每空2分,共20分)
27.方法void moveOddForword(int a[ ])的功能是将数组中的所有奇数移到所有偶数之前。
void moveOddFor
word(int a[]){
for(int i=0, odd=0;________;i++) i
自考乐园,自考学习交流、资料共享的好去处!自考乐园,自考人自己的家园....
俱乐部id:5346389(请牢记它哦~在百度贴吧的搜索框中输入俱乐部id,可以直接进入俱乐部
2
更多优质自考资料尽在百度贴吧自考乐园俱乐部
(tieba.baidu/club/5346389)欢迎?加入...欢迎?交流...止不住的惊喜等着你.........
if(________){ a[i]%2= =0
int t=a[i];a[i]=a[odd];a[odd]=t;odd++;
}
}
28.以下程序创建了一个窗口,然后在窗口内显示″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. ________; setVisable(true)
}
}
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. ________; paintComponent(g)
g.drawString(″Hello,World! ″,x,y);
}
public int x=100; public int y=100;
}
29.以下是子窗口中设置一个菜单条类的定义。类的构造方法根据指定的窗口名称和菜单表设置菜单条,菜单和菜单项,当选中某个菜单项时,在文本框中显示相应菜单项被选中的信息。
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();
自考乐园,自考学习交流、资料共享的好去处!自考乐园,自考人自己的家园....
俱乐部id:5346389(请牢记它哦~在百度贴吧的搜索框中输入俱乐部id,可以直接进入俱乐部
3
更多优质自考资料尽在百度贴吧自考乐园俱乐部
(tieba.baidu/club/5346389)欢迎?加入...欢迎?交流...止不住的惊喜等着你.........
for(int i=0; i JMenu menu=new JMenu(menuList[i][0]);
for(int j=1;j JMenultem anltem=new JMenultem(menuList[i][j]);
anltem.setActionCommand(menuList[i][j]);
anltem.________;menu.add(anltem); ActionListener(this)
}
menubar.__________; add(menu)
}
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.以下是一个用鼠标自由作画的小应用程序。最简单的方法是根据鼠标所在位置画点,跟随鼠标的移动,不断画圆点,就能实现用鼠标作画。
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);
}
}
自考乐园,自考学习交流、资料共享的好去处!自考乐园,自考人自己的家园....
俱乐部id:5346389(请牢记它哦~在百度贴吧的搜索框中输入俱乐部id,可以直接进入俱乐部
4
更多优质自考资料尽在百度贴吧自考乐园俱乐部
(tieba.baidu/club/5346389)欢迎?加入...欢迎?交流...止不住的惊喜等着你.........
public void mouseMoved(MouseEvent e){}
public void mouseDragged(MouseEvent e){
x=e.getX();y=e.getY();_________; repaint()
}
public void ________ (Graphics g){ paint(g);} update();
}
31.以下定义的类ShareData用于管理多个线程共享数据data。一个线程生成data,另一个线程使用data。约定,新生成的data只有被另一个线程使用后,才能生成下一个data。反之,一个data被使用后,也不能再继续使用。所以,生成和使用data的线程之间需要互斥和同步。以下是管理上述使用方式的类,类内有要管理的共享数据,以及对共享数据的存操作putData()和取操作getData()。
class ShareData{
int data;∥共享数据
boolean newData=false;∥有最近新生成data的标志
synchronized int getData(){
while(!newData){
try{ _________; wait()
} catch(InterruptedExceptipn e){
System.out.println(″因错误,而中断!″);
}
}
newData=false; notify();return data;
}
synchronized void putData(int n){
while(newData){
try{wait();
}catch(