云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > JAVA期末复习资料2

JAVA期末复习资料2

  • 62 次阅读
  • 3 次下载
  • 2025/7/4 16:14:36

private int m_id;

public (2)_________(Socket s, int id) { m_socket= s; m_id= id; }

public void (3)_______{

try {(4)_______. sleep(10000);

System.out.println(\ m_socket.close();

} catch (Exception e) {} }

public static void main(String args[]){ int n= 1;

_(5)_________ server= null; try{

server= new (6)____________(5000); System.out.println( \ }

catch (IOException e){} while (true){ try{

System.out.println(\(7)_________ s= server.accept( );

ServerExample t=new ServerExample(s, n++);

(8)_________ th =new Thread(t); (9)______.start( ); }

catch (IOException e){}

} // End of loop: while } // End of method: main }

2、下面是一个支持多个客户端交互的程序,请根据注释要求补充、完成代码: importjava.io.*;

(1)________ //加载网络API包

public class ServerThread extends Thread{ Socket socket=null; int clientnum;

publicServerThread(Socket socket,int num) { this.socket=socket; clientnum=num+1; }

public void run() { try{

String line;

InputStream in=(2)_______________//得到socket的输入流

BufferedReader is=new BufferedReader(new InputStreamReader(in)); PrintWriteros=new PrintWriter(socket.getOutputStream());

//由系统标准输入设备构造BufferedReader对象 BufferedReader sin=new BufferedReader ((3)______________);

System.out.println(\line=sin.readLine();

while(!line.equals(\os.println(line);

//刷新输出流,使Client马上收到该字符串 (4)____________

System.out.println(\

System.out.println(\line=sin.readLine(); }

os.close();//关闭Socket输出流 is.close(); //关闭Socket输入流 socket.close(); //关闭Socket对象 }catch(Exception e){

System.out.println(\ } } }

3、定义类ThdTest,其父类为Thread类;并在主方法中创建一个ThdTest的对象,同时启动该线程对象。

//声明类ThdTest,其父类为Thread类 (1)___________________ {

public void run(){

for(int i = 0; i < 10; i++){

(2)___________________________//输出当前线程的名字和i的值 try{

(3)__________________//让当前线程休眠100ms }catch(Exception e){ e.printStackTrace ();} } } }

public class Demo{

public static void main(String[] args){

(4)___________________//创建一个ThdTest的对象

(5)________________//启动线程对象,使其进入就绪状态

} }

4、下面的程序利用线程输出从a到z的26个字母,每隔一秒钟输出一个字母,程序不完整,请阅读程序代码,根据注释要求在划线处补充完成代码。 public class Test4 implements Runnable {

charcharArray[]=new char[26]; public Test4() {

for(int i = 0; i

charArray[i]=(char)(i+'a'); } }

public void run() { try {

for (int i = 0; i

(1)____________//休眠一秒钟 System.out.print(charArray[i]); } }

catch (InterruptedException e) {

e.printStackTrace(); } }

public static void main(String args[]) {

Thread t = _(2)______________//实例化线程对象 (3)________________//启动线程 } }

5、定义类ThdDemo,实现接口Runnable;并在主方法中创建一个ThdDemo的对象td,然后使用对象td创建一个线程对象,同时启动该线程对象。 //声明类ThdDemo,实现接口Runnable (1)__________________

classThdDemo implements Runnable{ public void run(){

for(int i = 0; i < 10; i++){

//输出当前线程的名字和i的值

System.out.println(Thread.currentThread().getName() + “:” + i); try{

(2)_______________//让当前线程休眠100ms }catch(Exception e){ e.printStackTrace ();} } } }

public class Demo{

public static void main(String[] args){

_(3)_______________//创建一个ThdDemo的对象td _(4)_____________//使用td创建线程对象

_(5)_______________//启动线程对象,使其进入就绪状态 } }

6、制作一个Applet小应用程序,设置其布局为BorderLayout,定义一个按钮和多行文本框并分别放到 “North”区域和“Center”区域。创建网页文件运行这个Applet程序。 importjava.applet.*; importjavax.swing.*;

_(1)______________________________________________________//声明AppletDemo类,其父类为Applet,并实现接口ActionListener {

Jbutton btn;

JTextArea txt; public void init(){

_(2)_________________________//设置其布局为BorderLayout btn = new JButton(“Show Msg”); txt = new JTextArea(3, 20);

_______________________ //把按钮btn放到“North”区域,txt放到“Center”区域

(3)_______________________

_(4)_______________________//给按钮注册监听器 }

public void actionPerformed(ActionEvent e){ txt.append(btn.getText()); } }

网页文件为:

搜索更多关于: JAVA期末复习资料2 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

private int m_id; public (2)_________(Socket s, int id) { m_socket= s; m_id= id; } public void (3)_______{ try {(4)_______. sleep(10000); System.out.println(\ m_socket.close(); } catch (Exception e) {} } public static void main(String args[]){ int n= 1; _(5)_________ server= null; try{ server= new (6

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com