一个用java编写的即时聊天程序

玛丽莲梦兔
524次浏览
2020年08月02日 09:12
最佳经验
本文由作者推荐

有的放矢的读音-乘积是什么意思


一个用java编写的即时聊天程序
import .*;
import .*;
import .*;

/**
* Sample application using Frame.
*
* @author
* @version 1.00 07/06/13
*/
public class Chatp2pFrame extends Frame {
List dataList=new List(26);
TextField Tfip=new TextField(18);
TextField Tfdata=new TextField(19);
Label Lip=new Label("输入对方的IP地址:");
Label Ldata=new Label("输入聊天的内容:");
DatagramSocket socket=null;
/**
* The constructor.
*/
public Chatp2pFrame() {
try
{
socket=new DatagramSocket(5000);
}
catch(Exception e)
{
tackTrace();

}

e(150,15);
e(150,15);
usable(true);
eground();
eground();
eground();
(dataList,"North");
Panel p1=new Panel();
Panel p2=new Panel();
out(new BorderLayout());
out(new BorderLayout());
(p1,"Center");
(p2,"South");
(Lip,"West");
(Ldata,"East");
(Tfip,"West");
(Tfdata,"East");

new Thread(new Runnable()
{
public void run()
{
byte[] buf=new byte[1024];
DatagramPacket packet=new DatagramPacket(buf,1024);
while(true)
{
try
{
e(packet);
(new String(buf,0,gth())+" FROM "+ress().getHostAddress()+":"+t(),0);
}
catch(Exception e)
{
if(!ed())
{
tackTrace();
}
}
}
}

}
).start();

ionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
byte[] buf=new byte[1024];
buf=t().getBytes();
DatagramPacket packet=new DatagramPacket(buf,,
ame(t()),5000);
(packet);
(new String(buf,0,gth())+" TO "+ress().getHostAddress()+":"+t(),0);
}
catch(Exception x)
{
tackTrace();
}
t("");
}
}
);
MenuBar menuBar = new MenuBar();
Menu menuFile = new Menu();
MenuItem menuFileExit
= new MenuItem();

el("文件");
el("退出");

// Add action the menu button
ionListener
(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
Closed();
}
}
);
(menuFileExit);
(menuFile);

setTitle("我的聊天程序");
setMenuBar(menuBar);
setSize(new Dimension(310, 500));
izable(false);

// Add window listener.
dowListener
(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
Closed();
}
}
);
}


/**
* Shutdown procedure when run as an application.
*/
protected void windowClosed() {

// TODO: Check if it is safe to close the application

// Exit application.
();
(0);
}



public static void main(String[] args) {
// Create application frame.
Chatp2pFrame frame = new Chatp2pFrame();

// Show frame
ible(true);
}
}

难道近义词-钟灵毓秀的意思


孑然一身是什么意思-绥远在哪


结尾的作用-捷报的意思


碘酒是什么-如臂使指


tomato是什么意思-竞选


博士英文缩写-企望


形容玉石的优美句子-励精图治


guitar怎么读-拜服翻译