毕业论文论文范文课程设计实践报告法律论文英语论文教学论文医学论文农学论文艺术论文行政论文管理论文计算机安全
您现在的位置: 毕业论文 >> 课程设计 >> 正文

java聊天程序Socket+Java聊天程序源代码 第2页

更新时间:2011-7-16:  来源:毕业论文
JScrollPane jsp=new JScrollPane(t3);
  JScrollPane jsp1=new JScrollPane(t2);
  JPanel p=new JPanel();//定义一个p面板
  JPanel p1=new JPanel();
  JPanel p2=new JPanel();
  String tt1=null;
  String str=null;//用于接受存储客户端的字符串变量
  boolean Listening=true;int number=0;
  DataOutputStream dd=null;
  
 Server(){
 t2.setText("显示客户端聊天的内容:");
 this.setTitle("服务器端已经启动........");
 this.setLayout(new FlowLayout());//定义JFrame的布局管理器为FlowLayout类型
    this.setSize(580,520);//定义JFrame的大小
    this.setLocation(300,200);//定义JFrame的位置坐标
 p.setBackground(new Color(10,150,92));//定义面板p的背景颜色
 t1.addActionListener(new Tevent());

 p.add(t1);//添加t1进面板p中
 p.add(tt);//添加显示获取到的本机的IP地址用于给不同一台电脑的客户端登陆
 tt.setText("服务器的IP地址为:"+adr.getAddress());
 p.add(jj1);
 p.add(jsp);
 p1.add(jsp1);//添加t2进去面板p1
 t2.setBackground(new Color(120,195,188));
 p2.add(jj);  //添加显示在线人数的文本框jj
 p2.add(jb);  //添加显示在线人数文本域
 
 this.getContentPane().add(p2,  BorderLayout.NORTH);//把面板p2放在JFrame的上方
 this.getContentPane().add(p1,  BorderLayout.CENTER);//把面板p1放在JFrame的中间方
 this.getContentPane().add(p,  BorderLayout.SOUTH);//把面板p放在JFrame的下方
 this.setVisible(true);//设置JFrame为可见
    setResizable(false);//设置JFrame框架不可以改变大小
 this.setDefaultCloseOperation(EXIT_ON_CLOSE);//关闭窗口方法
 }
 class Tevent implements ActionListener{
  public void actionPerformed(ActionEvent e) {
      tt1=t1.getText();    
      t1.setText("");
      t2.setText(t2.getText()+"\n"+"服务器:"+tt1);//把消息显示在服务器面板t2文本域中
     try {
   dd.writeUTF(tt1);
   str=tt1;
   
  } catch (IOException e1) {
   
   e1.printStackTrace();
  }
  }

  
 }
 //用Address类获取本地服务器的IP地址,不同一台电脑的客户端就靠此ip登陆
 class Address {论文网http://www.youerw.com/
        private String ip;
        public String getAddress(){
        try{
            InetAddress address = InetAddress.getLocalHost();
            ip= address.getHostAddress().toString();
        }catch(Exception e){
            ip = "无法获得IP";
        }
        return ip;
        }
    }
 public static void main(String[] args) {
  new Server().start();//在主方法mian调用start()
  
 }
 
 public void start() {
  try {
   ss = new ServerSocket(8888);//监听端口号为8888
   started = true;
  } catch (IOException e) {
   e.printStackTrace(); JScrollPane jsp=new JScrollPane(t3);
  JScrollPane jsp1=new JScrollPane(t2);
  JPanel p=new JPanel();//定义一个p面板
  JPanel p1=new JPanel();
  JPanel p2=new JPanel();
  String tt1=null;
  String str=null;//用于接受存储客户端的字符串变量
  boolean Listening=true;int number=0;
  DataOutputStream dd=null;
  
 Server(){
 t2.setText("显示客户端聊天的内容:");
 this.setTitle("服务器端已经启动........");
 this.setLayout(new FlowLayout());//定义JFrame的布局管理器为FlowLayout类型
    this.setSize(580,520);//定义JFrame的大小
    this.setLocation(300,200);//定义JFrame的位置坐标
 p.setBackground(new Color(10,150,92));//定义面板p的背景颜色
 t1.addActionListener(new Tevent());

 p.add(t1);//添加t1进面板p中
 p.add(tt);//添加显示获取到的本机的IP地址用于给不同一台电脑的客户端登陆
 tt.setText("服务器的IP地址为:"+adr.getAddress());
 p.add(jj1);原文请找腾讯752018766
 p.add(jsp);
 p1.add(jsp1);//添加t2进去面板p1
 t2.setBackground(new Color(120,195,188));
 p2.add(jj);  //添加显示在线人数的文本框jj
 p2.add(jb);  //添加显示在线人数文本域
 
 this.getContentPane().add(p2,  BorderLayout.NORTH);//把面板p2放在JFrame的上方
 this.getContentPane().add(p1,  BorderLayout.CENTER);//把面板p1放在JFrame的中间方
 this.getContentPane().add(p,  BorderLayout.SOUTH);//把面板p放在JFrame的下方
 this.setVisible(true);//设置JFrame为可见
    setResizable(false);//设置JFrame框架不可以改变大小
 this.setDefaultCloseOperation(EXIT_ON_CLOSE);//关闭窗口方法
 }
 class Tevent implements ActionListener{
  public void actionPerformed(ActionEvent e) {
      tt1=t1.getText();    
      t1.setText("");
      t2.setText(t2.getText()+"\n"+"服务器:"+tt1);//把消息显示在服务器面板t2文本域中
     try {
   dd.writeUTF(tt1);
   str=tt1;
   
  } catch (IOException e1) {
   
   e1.printStackTrace();
  }
  }

  
 }
 //用Address类获取本地服务器的IP地址,不同一台电脑的客户端就靠此ip登陆
 class Address {论文网http://www.youerw.com/
        private String ip;
        public String getAddress(){
        try{
            InetAddress address = InetAddress.getLocalHost();
            ip= address.getHostAddress().toString();
        }catch(Exception e){
            ip = "无法获得IP";
        }
        return ip;
        }
    }
 public static void main(String[] args) {
  new Server().start();//在主方法mian调用start()
  
 }
 
 public void start() {
  try {
   ss = new ServerSocket(8888);//监听端口号为8888
   started = true;
  } catch (IOException e) {
   e.printStackTrace();

上一页  [1] [2] [3] 下一页

java聊天程序Socket+Java聊天程序源代码 第2页下载如图片无法显示或论文不完整,请联系qq752018766
设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优文论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。