java双人聊天代码 java聊天程序设计代码

急求一个JAVA编写的局域网聊天代码?不要求很复杂 。只要可以在两台机子上简单的对话就可以 。//以下引入包
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.applet.*;
public class regit extends JApplet implements ActionListener,ItemListener//接口
{
String s=null;
//对象的声明
JLabel labelname,labelpass,labelsxe,labeladdress,labelmail,labelphone;//标签
JTextField textname,textaddress,textmail,textphone;//文本框
JRadioButton r1,r2;//单选按纽
ButtonGroup bg;//组
JPasswordField textpass;//密码域
JButton buttonregit,buttonreset;//注册按纽 重写按纽
JPanel p;//面板
【java双人聊天代码 java聊天程序设计代码】String sex;//定义性别字符串
URL url;//统一资源定位
BufferedWriter out1,out2;//流
BufferedReader in;
//布局方式
GridBagLayout gbl;
GridBagConstraints gc;
AppletContext co;//接口
//初始化
public void init()
{
//new 对象
labelname=new JLabel("用 户 名:");
labelpass=new JLabel("用户密码:");
labelsxe=new JLabel("性别:");
labeladdress=new JLabel("地址:");
labelmail=new JLabel("电子邮件:");
labelphone=new JLabel("联系电话:");
textname=new JTextField(15); textname.setForeground(Color.red);
textname.setToolTipText("请在这输入你的用户名");
textaddress=new JTextField(15);textaddress.setForeground(Color.red);
textaddress.setToolTipText("请在这输入你的地址");
textmail=new JTextField(15); textmail.setForeground(Color.red);
textmail.setToolTipText("请在这里输入你的E-mail地址");
textphone=new JTextField(15); textphone.setForeground(Color.red);
textphone.setToolTipText("请在这输入你的电话号码");
r1=new JRadioButton("男"); r1.setBackground(new Color(47,177,210));//设置颜色
r2=new JRadioButton("女"); r2.setBackground(new Color(47,177,210));//设置颜色
bg=new ButtonGroup();
bg.add(r1);bg.add(r2);//加入组,实现单选
textpass=new JPasswordField(15);
textpass.setToolTipText("在这里输入密码");
textpass.setForeground(Color.red);
buttonregit=new JButton("注册"); buttonregit.setBackground(new Color(47,177,210));//设置颜色
buttonregit.setToolTipText("点击按纽完成注册");
buttonreset=new JButton("填写"); buttonreset.setBackground(new Color(47,177,210));//设置颜色
buttonreset.setToolTipText("点击按纽刷新重写");
gbl=new GridBagLayout(); ///////////////////////////////////////
gc=new GridBagConstraints(); //////采用GridBagLayout布局方式////////
p=new JPanel();
p.setLayout(gbl);
p.setBackground(new Color(47,177,210));
this.getContentPane().add(p);//加入面板
gc.anchor=GridBagConstraints.NORTHWEST;
gc.gridx=2;
gc.gridy=2;
gbl.setConstraints(labelname,gc);
p.add(labelname);
gc.anchor=GridBagConstraints.NORTHWEST;
gc.gridx=4;
gc.gridy=2;
gbl.setConstraints(textname,gc);
p.add(textname);
gc.anchor=GridBagConstraints.NORTHWEST;
gc.gridx=2;
gc.gridy=4;
gbl.setConstraints(labelpass,gc);
p.add(labelpass);
gc.anchor=GridBagConstraints.NORTHWEST;
gc.gridx=4;
gc.gridy=4;
gbl.setConstraints(textpass,gc);
p.add(textpass);
gc.anchor=GridBagConstraints.NORTHWEST;
gc.gridx=2;
gc.gridy=6;
gbl.setConstraints(labelsxe,gc);
p.add(labelsxe);
gc.anchor=GridBagConstraints.NORTHWEST;
gc.gridx=4;
gc.gridy=6;
gbl.setConstraints(r1,gc);
p.add(r1);
gc.anchor=GridBagConstraints.NORTHWEST;
gc.gridx=5;
gc.gridy=6;
gbl.setConstraints(r2,gc);
p.add(r2);

推荐阅读