关键词不能为空

当前您在: 主页 > 英语 >

JAVA的即时通讯源代码

作者:高考题库网
来源:https://www.bjmy2z.cn/gaokao
2021-02-01 23:49
tags:

-

2021年2月1日发(作者:迭起)


JAVA


实现即使通讯的代码



图形界面




///////////////////////////////////////////////// /////////




//




Java


编写的聊天器,可以当



服务器



或者



是客户端,一对一,自定义对方



IP




端口。




//


虽然名为



LANChat


,但不限于局域网。对象甚至可以是某种



服务器






//////////// ///////////////////////////////////////////////




import


.*;



import


.*;



import


.*;



import


.*;



import


.*;




////////////////////////////////////////////////// ////////




public


class


LANChatV12{



public


static


void


m


ain(String


args[]){



LoginFrame


lf


=



new


LoginFrame(


输入目标




();



}



}



< /p>


//////////////////////////////////////// /////////////////




class


LoginFrame


extends


JFrame{



JButton


BOK;



JLabel


LdesAddr,


Lport;



JTextField


TFdesAddr,


TFport;



String


desAddr,


port;




LoginFrame(){}




LoginFrame(String


title){



super(title);



Fram


e


t


=



this;



BOK


=



new


JButton(


确定




LdesAddr


=



new


JLabel(


目标



IP



Lport


=



new


JLabel(


端口





TFdesAddr


=



new


JTextField(desAddr,12);



TFport


=



new


JTextField(port,12);



//oChar('*');



ionListener(new


BOKListener(t));



setBackground();



setBounds(350,250,200,128);



setLayout(new


FlowLayout(,5,7));



add(LdesAddr);



add(TFdesAddr);



add(Lport);



add(TFport);



add(BOK);



setResizable(false);



//setVisible(true);



addWindowListener(new


WindowAdapter(){



public


void


windowClosing(WindowEvent


e){



System


.exit(0);



}



});



}




class


BOKListener


implements


ActionListener{



Fram


e


t;




BOKListener(){}




BOKListener(Frame


t){



this.t


=



t;



}




public


void


actionPerformed(ActionEvent


e){



desAddr


=



t();



port


=



t();


ible(false);



Messenger


m


=



new


Messenger(desAddr,


port);



();



}



}



}




// ////////////////////////////////////////////////// /




class


Messenger


extends


Thread{



String


desAddr;



String


port;



int


iport;



TextArea


content,


send;



JButton


Bsend;



ChatFram


e


cf;



String


title;



Socket client;



ServerSocket


ss;



OutputStream


Writer


osw


=



null;



InputStreamReader


isr


=



null;



BufferedReader


br;



String


line;



boolean


flag;//


端口号是否正确




boolean


cbc;


//can


be client


?



int


tryTurns


=



3;


//


客户方式尝试的次数





Messenger(){}




Messenger(String


desAddr,


String


port){



super(



content


=



new


TextArea(



send


=



new


TextArea(


ICAL_ONLY);



Bsend


=



new


JButton(


发送




bled(false);



title


=







+


desAddr


+


聊天




flag


=



true;



cbc


=



true;




cf


=



new


ChatFram


e(title,


content,


send,


Bsend);



();




r


=



desAddr;




=



port;



try{



iport


=



nt(port);



}catch(NumberFormatException


nfe){



(


非法的



端口,程序



4


秒后关闭。


n



flag


=



false;



}



}




public


void


run(){



if(!


flag){



try{



(4000);



}catch(InterruptedException


ie){



System


.exit(0);



}



System


.exit(0);



}



-


-


-


-


-


-


-


-



本文更新与2021-02-01 23:49,由作者提供,不代表本网站立场,转载请注明出处:https://www.bjmy2z.cn/gaokao/595920.html

JAVA的即时通讯源代码的相关文章