1、[ 单选题 ]在Java语言中,支持网络通信的软件所在的包是()
A、java.util
B、java.net
C、java.io
D、java.internet
2、[ 主观题 ]【程序分析题】阅读下列程序,写出程序功能。
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);
}
}
3、[ 主观题 ]【简答题】JDBC是Java程序与数据库连接的API,请写出它能做哪三件事?
4、[ 主观题 ]【程序填空题】设计一个JFrame窗口,窗口中心有一个文本区。另有4个菜单,每个菜单都有菜单项,每个菜单项都对应有快捷键,选择某个菜单项时,窗口中心的文本区显示相应信息。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class C2902 implements ActionListener
{
___
JTextField text=new JTextField(20);
String t[]={"文件","编辑","格式","帮助"};
Menu menu[]=new Menu[4];
String s[]={"打开","保存","复制","粘贴","字体","段落","小助手","关于"};
MenuItem jmi[]=new MenuItem[8];
C2902()
{
JFrame myWin=new JFrame("Ex0606");
myWin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container con=myWin.getContentPane();
con.add(text,"Center");
text.setEditable(false);
myWin.setMenuBar(jmb);
int i;
for(i=0;i<4;i++)//生成四个菜单
{
menu[i]=new Menu(t[i]);
jmb.add(menu[i]);
}
for(i=0;i<8;i++)//每个菜单中放两个菜单项
{
jmi[i]=new MenuItem(s[i]);
menu[i/2].add(jmi[i]);
jmi[i].addActionListener(this);
jmi[i].___(new MenuShortcut(65+i));//设快捷键
}
myWin.setBounds(300,200,400,200);
myWin.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
text.setText("你选择了:"+e.getActionCommand()+"菜单项.");
}
public static void main(String[] args)
{
new C2902();
}
}
5、[ 主观题 ]【程序分析题】阅读下面程序,写出程序功能。
import java.applet.*;import java.awt.*;
public class Class3602 extends Applet implements Runnable
{
Thread redBall,blueBall;Graphics redPen,bluePen;
int blueSeta=0,redSeta=0;
public void init()
{
setSize(250,200);
redBall=new Thread(this);blueBall=new Thread(this);
redPen=getGraphics();bluePen=getGraphics();
redPen.setColor(Color.red);bluePen.setColor(Color.blue);
setBackground(Color.gray);
}
public void start()
{
redBall.start();blueBall.start();
}
public void run()
{
int x,y;
while(true)
{
if(Thread.currentThread()==redBall)
{
x=(int)(80.0*Math.cos(3.1415926/180.0*redSeta));
y=(int)(80.0*Math.sin(3.1415926/180.0*redSeta));
redPen.setColor(Color.gray);
redPen.fillOval(100+x,100+y,10,10);
redSeta +=3;
if(redSeta>=360) redSeta=0;
x=(int)(80.0*Math.cos(3.1415926/180.0*redSeta));
y=(int)(80.0*Math.sin(3.1415926/180.0*redSeta));
redPen.setColor(Color.red);
redPen.fillOval(100+x,100+y,10,10);
try {redBall.sleep(20);}
catch(InterruptedException e){}
}
else if (Thread.currentThread()==blueBall)
{
x=(int)(80.0*Math.cos(3.1415926/180.0*blueSeta));
y=(int)(80.0*Math.sin(3.1415926/180.0*blueSeta));
bluePen.setColor(Color.gray);
bluePen.fillOval(150+x,100+y,10,10);
blueSeta-=3;
if(blueSeta<=-360) blueSeta=0;
x=(int)(80.0*Math.cos(3.1415926/180.0*blueSeta));
y=(int)(80.0*Math.sin(3.1415926/180.0*blueSeta));
bluePen.setColor(Color.blue);
bluePen.fillOval(150+x,100+y,10,10);
try {blueBall.sleep(40);}
catch(InterruptedException e){}
}
}
}
}