📄 client.java
字号:
/**
* Created by IntelliJ IDEA.
* User: ${040421220 郑天南}
* Date: 2007-4-12
* Time: 13:53:50
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.net.Socket;
import java.net.InetAddress;
import java.io.*;
public class Client
{
public static void main(String[] args)
{
/* clFrame frame=new clFrame();
frame.setDefaultCloseOperation(clFrame.EXIT_ON_CLOSE);
frame.setVisible(true); */
}
}
class clFrame extends JFrame
{
public clFrame()
{
dimframe=new Dimension(500,550);
this.setSize(dimframe);
this.setTitle("Winock-Client");
Container cp=getContentPane();
clPanel panel=new clPanel();
cp.add(panel);
}
private Dimension dimframe;
}
class clPanel extends JPanel
{
public clPanel()
{
FlowLayout flow=new FlowLayout();
setLayout(flow);
label1=new JLabel("The Message you received");
add(label1);
recvtext=new JTextArea(10,40);
add(recvtext);
label2=new JLabel("The Message you will send");
add(label2);
sendtext=new JTextArea(10,40);
add(sendtext);
sendbutton=new JButton("Send");
sendbutton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
sendmessage();
}
});
add(sendbutton);
}
//发送消息
private void sendmessage()
{
try
{
clsocket=new Socket(InetAddress.getLocalHost(),6629);
String text=sendtext.getText();
PrintWriter textsend=new PrintWriter(clsocket.getOutputStream());
textsend.println(text);
textsend.flush();
clsocket.shutdownOutput();
BufferedReader in=new BufferedReader(new InputStreamReader(clsocket.getInputStream()));
recvtext.setText(in.readLine());
in.close();
}
catch(IOException ex)
{
}
}
private Socket clsocket;
private JLabel label1;
private JLabel label2;
private JLabel label3;
private JTextField info;
private JTextArea sendtext;
private JTextArea recvtext;
private JButton sendbutton;
private JButton submit;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -