java通信Word格式文档下载.docx
- 文档编号:15159686
- 上传时间:2022-10-28
- 格式:DOCX
- 页数:52
- 大小:36.32KB
java通信Word格式文档下载.docx
《java通信Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《java通信Word格式文档下载.docx(52页珍藏版)》请在冰豆网上搜索。
,5000);
in=newDataInputStream(mysocket.getInputStream());
out=newDataOutputStream(mysocket.getOutputStream());
out.writeUTF("
你好啊"
);
while(true)
s=in.readUTF();
if(s==null)break;
}//从服务器线路中读取信息!
mysocket.close();
}
catch(IOExceptione){System.out.println("
发生意外阿,现在确实是无法连接,请稍候....."
System.out.println(s);
=---------------------------------------------------------------------------------------------------------------------------------------
//以上实验:
JAVA网络程序设计成功实现本机通讯!
publicclassServer
{ServerSocketserver=null;
//
Socketyou=null;
//服务器端的socket对象!
try{server=newServerSocket(5000);
catch(IOExceptione1){System.out.println("
ERRO:
"
+e1);
try
{you=server.accept();
in=newDataInputStream(you.getInputStream());
out=newDataOutputStream(you.getOutputStream());
{s=in.readUTF();
if(s!
=null)
break;
你好!
服务器受到了你发的信息!
//通过out向线路写入信息!
client接受信息!
you.close();
catch(IOExceptione)
{System.out.println("
+e);
==========================================================================
importjava.applet.*;
importjava.awt.*;
publicclassWuqiongextendsApplet
staticImageimg;
Canvascanvas;
staticintwidth,height;
publicvoidinit()
setLayout(newGirlLayout(3,1);
addf(newButton("
祝愿"
));
add(newButton("
进步"
canvas=newMycanvas();
add(canvas);
width=getSize().width;
height=getSize().height;
publicvoidstart()
{img=getImage(getCodeBase(),"
20041.jpg"
classMycanvasextendsCancas
publicvoidpaint(Graphicsg)
{g.drawImage(Wuqiong.img,0,0,Wuqiong.width,(Wuqiong.height)/3,this);
}
51 第2楼
//importjava.awt.TextField;
//importjava.awt.TextArea;
importjava.awt.event.*;
publicclasswenbenquceshiextendsAppletimplementsTextListener
{//处理文本框事件的接口!
TextAreatext1,text2;
TextFieldtext3;
text1=newTextArea("
"
10,10);
text2=newTextArea("
text3=newTextField(10);
add(text1);
add(text2);
add(text3);
text1.addTextListener(this);
//将珠主类的实例作为监听器!
//实例必须实现接口方法!
publicvoidtextValueChanged(TextEvente)//
{if(e.getSource()==text1)
{text2.setText(text1.getText());
text3.setText("
我开始要改变内容"
else{}
48:
06 第3楼
publicclasswenbenkuangextendsAppletimplementsActionListener
TextFieldtext1,text3;
{setBackground(Color.green);
setSize(300,300);
text1=newTextField(10);
text1.addActionListener(this);
publicvoidactionPerformed(ActionEvente)//当前类对象作为监视器并且实现接口方法,通过该方法来处理文本事件的方法!
{//文本框这个事件源可以发生ActionEvent事件!
//
if((e.getSource()==text1)&
&
(text1.getText().equals("
boy"
)))
{text3.setText("
男孩"
elseif((e.getSource()==text1)&
girl"
{text3.setText("
女孩"
sun"
太阳"
else
没有这个单词阿!
22 第4楼
publicclassStringindexextendsApplet
Stringtom="
Iamagoodbook!
;
intx,y,z;
booleanm;
{tom=newString("
{m=tom.startsWith("
I"
x=tom.indexOf("
a"
y=tom.indexOf("
good"
2);
z=tom.indexOf("
7);
g.setColor(Color.red);
g.drawString("
+x+"
:
+y+"
+z+"
+m,20,30);
45 第5楼
publicclassnetextendsAppletimplementsActionListener
{//理解监听器与接口的作用和关系!
Choicechoice;
Buttonbutton;
URLurl;
TextFieldtext;
Strings1,s2,s3,s4;
setLayout(newGridLayout(2,1));
text=newTextField(10);
button=newButton("
确定"
choice=newChoice();
s1="
s2="
s3="
s4="
choice.add(s1);
choice.add(s2);
choice.add(s3);
choice.add(s4);
add(choice);
add(button);
add(text);
//注意要将组件放入容器中!
add(newLabel());
button.addActionListener(this);
//当前类对象
publicvoidactionPerformed(ActionEvente)//当时间源发生事件时,监视器自动调用对应的接口方法对时间进行处理!
if(e.getSource()==button)
{try
{url=newURL(choice.getSelectedItem().trim());
text.setText("
请等待......"
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- java 通信