📄 client_bkp.java
字号:
//client.java
/**
@author Joedan
*/
import javax.swing.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
public class client extends JFrame implements Runnable, ActionListener
{
DatagramSocket s;
DatagramPacket ps;
byte [] buffer = new byte[512];
DatagramPacket pr = new DatagramPacket(buffer, 0, buffer.length);
String msg;
JButton btn = new JButton("Send");
JTextArea txt = new JTextArea();
client()
{
super("client");
try
{
s = new DatagramSocket(5050);
ps = new DatagramPacket("".getBytes(), 0, InetAddress.getLocalHost(), 5051);
}
catch(Exception e)
{
}
setBounds(400, 300, 200, 150);
btn.addActionListener(this);
getContentPane().add(txt, "Center");
getContentPane().add(btn, "South");
setVisible(true);
addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
new Thread(this).start();
}
public void actionPerformed(ActionEvent e)
{
try
{
ps.setData(txt.getText().getBytes());
s.send(ps);
}
catch(IOException ee)
{
}
}
public void run()
{
while(true)
{
try
{
s.receive(pr);
txt.append(new String(pr.getData()).trim() + "\n");
}
catch(IOException e)
{
}
}
}
public static void main(String args[])
{
new client();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -