JAVA开发进阶实验报告模板Word格式.docx

上传人:b****6 文档编号:21331260 上传时间:2023-01-29 格式:DOCX 页数:15 大小:266.41KB
下载 相关 举报
JAVA开发进阶实验报告模板Word格式.docx_第1页
第1页 / 共15页
JAVA开发进阶实验报告模板Word格式.docx_第2页
第2页 / 共15页
JAVA开发进阶实验报告模板Word格式.docx_第3页
第3页 / 共15页
JAVA开发进阶实验报告模板Word格式.docx_第4页
第4页 / 共15页
JAVA开发进阶实验报告模板Word格式.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

JAVA开发进阶实验报告模板Word格式.docx

《JAVA开发进阶实验报告模板Word格式.docx》由会员分享,可在线阅读,更多相关《JAVA开发进阶实验报告模板Word格式.docx(15页珍藏版)》请在冰豆网上搜索。

JAVA开发进阶实验报告模板Word格式.docx

四、实验结果与数据处理

 

五、分析与讨论

编写的过程当中,客户端和服务端经常出现系统崩溃,后来才发现是编写的代码出现了问题,导致使用不了,后来在努力查找下终于实现了运行。

第二个实验也是,比较多的问题都是代码出错,表示写得有点纠结,不过之后经过修改就成功了。

发现细心很重要。

六、教师评语

签名:

日期:

成绩

列出程序代码:

(1)、

importjava.io.*;

import.*;

import.Socket;

publicclassServerThreadextendsThread{

privateSocketconnectToClient;

privateDataInputStreaminFromClient;

privateDataOutputStreamoutToClient;

publicServerThread(Socketsocket)throwsIOException{

super();

connectToClient=socket;

inFromClient=newDataInputStream(connectToClient.getInputStream());

outToClient=newDataOutputStream(connectToClient.getOutputStream());

start();

}

publicvoidrun(){

try{

Stringstr;

doubleradius,area;

booleangoon=true;

while(goon){

str=inFromClient.readUTF();

if(!

str.equals("

bye"

)){

radius=Double.parseDouble(str);

System.out.println("

接收到得半径值为:

"

+radius);

area=radius*radius*Math.PI;

str=Double.toString(area);

outToClient.writeUTF(str);

outToClient.flush();

圆面积"

+str+"

已经发送"

);

}else{

goon=false;

outToClient.writeUTF("

}

}

inFromClient.close();

outToClient.close();

connectToClient.close();

}catch(IOExceptione){

e.printStackTrace();

}

(2)

publicclassMultiServer{

publicstaticvoidmain(String[]args){

try{

System.out.println("

等待连接"

ServerSocketserverSocket=newServerSocket(3500);

SocketconnectToClient=null;

while(true){

connectToClient=serverSocket.accept();

newServerThread(connectToClient);

}catch(IOExceptione){

e.printStackTrace();

(3)

publicclassClient{

publicstaticvoidmain(String[]args){

SocketconnectToServer=newSocket("

localhost"

200);

DataInputStreaminFromServer=newDataInputStream(connectToServer.getInputStream());

DataOutputStreamoutToServer=newDataOutputStream(connectToServer.getOutputStream());

StringoutStr,inStr;

booleangoon=true;

BufferedReaderbuf=newBufferedReader(newInputStreamReader(System.in));

while(goon){

outStr=buf.readLine();

outToServer.writeUTF(outStr);

outToServer.flush();

inStr=inFromServer.readUTF();

if(!

inStr.equals("

))

System.out.println("

从服务器返回的结果是"

+inStr);

else

goon=false;

inFromServer.close();

outToServer.close();

connectToServer.close();

300055);

输入半径数值发送到服务器,输入bye结束。

(1)、importjava.io.*;

importjava.awt.*;

importjava.awt.Container;

importjava.awt.FlowLayout;

importjava.awt.event.*;

importjavax.swing.*;

publicclasschatServerimplementsActionListener,Runnable{

JTextAreashowArea;

JTextFieldmsgText;

JFramemainJframe;

JButtonsentBtn;

JScrollPaneJSPane;

JPanelpane;

Containercon;

Threadthread=null;

ServerSocketserverSocket;

SocketconnectToClient;

DataInputStreaminFromClient;

DataOutputStreamoutToClient;

publicchatServer(){

mainJframe=newJFrame("

聊天——服务器端"

con=mainJframe.getContentPane();

showArea=newJTextArea();

showArea.setEditable(false);

showArea.setLineWrap(true);

JSPane=newJScrollPane(showArea);

msgText.setColumns(30);

msgText.addActionListener(this);

sentBtn=newJButton("

发送"

sentBtn.addActionListener(this);

pane=newJPanel();

pane.setLayout(newFlowLayout());

pane.add(msgText);

pane.add(sentBtn);

con.add(JSPane,BorderLayout.CENTER);

con.add(pane,BorderLayout.SOUTH);

mainJframe.setSize(500,400);

mainJframe.setVisible(true);

mainJframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

serverSocket=newServerSocket(5500);

showArea.append("

正在等待对话请求\n"

connectToClient=serverSocket.accept();

inFromClient=newDataInputStream(connectToClient.getInputStream());

outToClient=newDataOutputStream(connectToClient.getOutputStream());

thread=newThread(this);

thread.setPriority(Thread.MIN_PRIORITY);

thread.start();

对不起,不能创建服务器\n"

msgText.setEditable(false);

sentBtn.setEnabled(false);

newchatServer();

publicvoidactionPerformed(ActionEvente){

Strings=msgText.getText();

if(s.length()>

0){

try{

outToClient.writeUTF(s);

showArea.append("

我说:

+msgText.getText()+"

\n"

}catch(IOExceptione1){

showArea.append("

你的消息:

”"

“未能发送出去\n"

publicvoidrun(){

while(true){

showArea.append("

对方说:

+inFromClient.readUTF()+"

Thread.sleep(1000);

}

}catch(IOExceptionel){

}catch(InterruptedExceptione){}

实验二

publicclasschatClientimplementsActionListener,Runnable{

SocketconnectToServer;

DataInputStreaminFromServer;

DataOutputStreamoutToServer;

publicchatClient(){

聊天----客户端"

msgText=newJTextField();

con.add(JSPane,BorderLayout.CENTER);

con.add(pane,BorderLayout.SOUTH);

connectToServer=newSocket("

5500);

inFromServer=newDataInputStream(

connectToServer.getInputStream());

outToServer=newDataOutputStream(

connectToServer.getOutputStream());

连接成功,请说话\n"

thread=newThread(this);

thread.setPriority(Thread.MIN_PRIORITY);

thread.start();

对不起,没能连接到服务器\n"

msgText.setEditable(false);

sentBtn.setEnabled(false);

publicstaticvoidmain(String[]args)

{newchatClient();

outToServer.writeUTF(s);

我说:

msgText.setText(null);

}catch(IOExceptionel){

未能发送出去\n"

+inFromServer.readUTF()+"

Thread.sleep(1000);

}catch(InterruptedExceptione){}

{}

服务端:

publicclasschatServerimplementsActionListener,Runnable

{

publicchatServer()

{

聊天----服务器端"

inFromClient=newDataInputStream(

connectToClient.getInputStream());

outToClient=newDataOutputStream(

connectToClient.getOutputStream());

对不起,不能创建服务器"

sentBtn.setEnabl

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 总结汇报 > 其它

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1