欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

java網(wǎng)頁(yè)聊天代碼,javaweb在線聊天系統(tǒng)

急需一個(gè)java編程實(shí)現(xiàn)的簡(jiǎn)單聊天窗口代碼

import java.awt.*;

“只有客戶發(fā)展了,才有我們的生存與發(fā)展!”這是成都創(chuàng)新互聯(lián)的服務(wù)宗旨!把網(wǎng)站當(dāng)作互聯(lián)網(wǎng)產(chǎn)品,產(chǎn)品思維更注重全局思維、需求分析和迭代思維,在網(wǎng)站建設(shè)中就是為了建設(shè)一個(gè)不僅審美在線,而且實(shí)用性極高的網(wǎng)站。創(chuàng)新互聯(lián)對(duì)成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、網(wǎng)站制作、網(wǎng)站開(kāi)發(fā)、網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站優(yōu)化、網(wǎng)絡(luò)推廣、探索永無(wú)止境。

import java.awt.event.*;

import javax.swing.*;

import java.net.*;

import java.io.*;

public class ClientDemo01 {

public static void main(String[] args){

JFrame f=new JFrame("AA");

JPanel p1=new JPanel();

JPanel p2=new JPanel();

JTextArea ta=new JTextArea(15,30);

ta.setEditable(false); //文本域只讀

JScrollPane sp=new JScrollPane(ta); //滾動(dòng)窗格

JTextField tf=new JTextField(20);

JButton b=new JButton("發(fā)送");

p1.add(sp);

p2.add(tf);

p2.add(b);

f.add(p1,"Center");

f.add(p2,"South");

f.setBounds(300,300,360,300);

f.setVisible(true);

f.setResizable(false);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Socket socket=null;

BufferedInputStream bis=null;

BufferedOutputStream bos=null;

try{

socket=new Socket("192.168.0.4",5000);

bis=new BufferedInputStream(socket.getInputStream());

bos=new BufferedOutputStream(socket.getOutputStream());

MyThread01 mt=new MyThread01(bis,ta);

mt.start();

}catch(Exception e){

e.printStackTrace();

}

b.addActionListener(new ButtonActionListener01(tf,ta,bos));

}

}

class ButtonActionListener01 implements ActionListener{

JTextField tf;

JTextArea ta;

BufferedOutputStream bos;

public ButtonActionListener01(JTextField tf,JTextArea ta,BufferedOutputStream bos){

this.tf=tf;

this.ta=ta;

this.bos=bos;

}

public void actionPerformed(ActionEvent e){

String message=tf.getText();

if(!message.equals("")){

tf.setText(""); //清空文本框

ta.append("AA:"+message+"\n"); //添加到文本域并換行

try{

bos.write(message.getBytes());

bos.flush();

}catch(Exception ex){

System.out.println("發(fā)送失敗");

}

}

}

}

class MyThread01 extends Thread{

BufferedInputStream bis;

JTextArea ta;

public MyThread01(BufferedInputStream bis,JTextArea ta){

this.bis=bis;

this.ta=ta;

}

public void run(){

try{

while(true){

byte[] b=new byte[100];

int length=bis.read(b);

String message=new String(b,0,length);

ta.append("BB:"+message+"\n");

}

}catch(Exception e){

e.printStackTrace();

}

}

} import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.net.*;

import java.io.*;

public class ServerDemo01{

public static void main(String[] args){

JFrame f=new JFrame("BB");

JPanel p1=new JPanel();

JPanel p2=new JPanel();

JTextArea ta=new JTextArea(12,30); //文本域,第一個(gè)參數(shù)為行數(shù),第二個(gè)參數(shù)為列數(shù)

ta.setEditable(false); //文本域只讀

JScrollPane sp=new JScrollPane(ta); //滾動(dòng)窗格

JTextField tf=new JTextField(20);

JButton b=new JButton("發(fā)送");

p1.add(sp);

p2.add(tf);

p2.add(b);

f.add(p1,"Center");

f.add(p2,"South");

f.setBounds(300,300,360,300);

f.setVisible(true);

f.setResizable(false);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

ServerSocket server=null;

Socket socket=null;

BufferedInputStream bis=null;

BufferedOutputStream bos=null;

try{

server=new ServerSocket(5000);

//ta.append("等待AA連接...\n");

socket=server.accept();

//ta.append("AA已連接\n");

bis=new BufferedInputStream(socket.getInputStream());

bos=new BufferedOutputStream(socket.getOutputStream());

MyThread1 mt=new MyThread1(bis,ta);

mt.start();

}catch(Exception e){

e.printStackTrace();

}

b.addActionListener(new ButtonActionListener1(tf,ta,bos));

}

}

class ButtonActionListener1 implements ActionListener{

JTextField tf;

JTextArea ta;

BufferedOutputStream bos;

public ButtonActionListener1(JTextField tf,JTextArea ta,BufferedOutputStream bos){

this.tf=tf;

this.ta=ta;

this.bos=bos;

}

public void actionPerformed(ActionEvent e){

String message=tf.getText(); //獲取文本框中的內(nèi)容

if(!message.equals("")){

tf.setText(""); //清空文本框

ta.append("BB:"+message+"\n"); //添加到文本域并換行

try{

bos.write(message.getBytes());

bos.flush();

}catch(Exception ex){

System.out.println("發(fā)送失??!");

}

}

}

}

class MyThread1 extends Thread{

BufferedInputStream bis;

JTextArea ta;

public MyThread1(BufferedInputStream bis,JTextArea ta){

this.bis=bis;

this.ta=ta;

}

public void run(){

try{

while(true){

byte[] b=new byte[100];

int length=bis.read(b);

String message=new String(b,0,length);

ta.append("AA:"+message+"\n");

}

}catch(Exception e){

e.printStackTrace();

}

}

}

用JAVA 編寫(xiě)簡(jiǎn)單網(wǎng)絡(luò)聊天程序

/**

* 基于UDP協(xié)議的聊天程序

*

* 2007.9.18

* */

//導(dǎo)入包

import java.awt.*;

import java.awt.event.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.*;

import java.net.*;

public class Chat extends JFrame implements ActionListener

{

//廣播地址或者對(duì)方的地址

public static final String sendIP = "172.18.8.255";

//發(fā)送端口9527

public static final int sendPort = 9527;

JPanel p = new JPanel();

List lst = new List(); //消息顯示

JTextField txtIP = new JTextField(18); //填寫(xiě)IP地址

JTextField txtMSG = new JTextField(20); //填寫(xiě)發(fā)送消息

JLabel lblIP = new JLabel("IP地址:");

JLabel lblMSG = new JLabel("消息:");

JButton btnSend = new JButton("發(fā)送");

byte [] buf;

//定義DatagramSocket的對(duì)象必須進(jìn)行異常處理

//發(fā)送和接收數(shù)據(jù)報(bào)包的套接字

DatagramSocket ds = null;

//=============構(gòu)造函數(shù)=====================

public Chat()

{

CreateInterFace();

//注冊(cè)消息框監(jiān)聽(tīng)器

txtMSG.addActionListener(this);

btnSend.addActionListener(this);

try

{

//端口:9527

ds =new DatagramSocket(sendPort);

}

catch(Exception ex)

{

ex.printStackTrace();

}

//============接受消息============

//匿名類(lèi)

new Thread(new Runnable()

{

public void run()

{

byte buf[] = new byte[1024];

//表示接受數(shù)據(jù)報(bào)包

while(true)

{

try

{

DatagramPacket dp = new DatagramPacket(buf,1024,InetAddress.getByName(txtIP.getText()),sendPort);

ds.receive(dp);

lst.add("【消息來(lái)自】◆" + dp.getAddress().getHostAddress() + "◆"+"【說(shuō)】:" + new String (buf,0,dp.getLength()) /*+ dp.getPort()*/,0);

}

catch(Exception e)

{

if(ds.isClosed())

{

e.printStackTrace();

}

}

}

}

}).start();

//關(guān)閉窗體事件

this.addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent w)

{

System.out.println("test");

int n=JOptionPane.showConfirmDialog(null,"是否要退出?","退出",JOptionPane.YES_NO_OPTION);

if(n==JOptionPane.YES_OPTION)

{

dispose();

System.exit(0);

ds.close();//關(guān)閉ds對(duì)象//關(guān)閉數(shù)據(jù)報(bào)套接字

}

}

});

}

//界面設(shè)計(jì)布局

public void CreateInterFace()

{

this.add(lst,BorderLayout.CENTER);

this.add(p,BorderLayout.SOUTH);

p.add(lblIP);

p.add(txtIP);

p.add(lblMSG);

p.add(txtMSG);

p.add(btnSend);

txtIP.setText(sendIP);

//背景顏色

lst.setBackground(Color.yellow);

//JAVA默認(rèn)風(fēng)格

this.setUndecorated(true);

this.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);

this.setSize(600,500);

this.setTitle("〓聊天室〓");

this.setResizable(false);//不能改變窗體大小

this.setLocationRelativeTo(null);//窗體居中

this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

this.setVisible(true);

txtMSG.requestFocus();//消息框得到焦點(diǎn)

}

//===============================Main函數(shù)===============================

public static void main(String[]args)

{

new Chat();

}

//================================發(fā)送消息===============================

//消息框回車(chē)發(fā)送消息事件

public void actionPerformed(ActionEvent e)

{

//得到文本內(nèi)容

buf = txtMSG.getText().getBytes();

//判斷消息框是否為空

if (txtMSG.getText().length()==0)

{

JOptionPane.showMessageDialog(null,"發(fā)送消息不能為空","提示",JOptionPane.WARNING_MESSAGE);

}

else{

try

{

InetAddress address = InetAddress.getByName(sendIP);

DatagramPacket dp = new DatagramPacket(buf,buf.length,InetAddress.getByName(txtIP.getText()),sendPort);

ds.send(dp);

}

catch(Exception ex)

{

ex.printStackTrace();

}

}

txtMSG.setText("");//清空消息框

//點(diǎn)發(fā)送按鈕發(fā)送消息事件

if(e.getSource()==btnSend)

{

buf = txtMSG.getText().getBytes();

try

{

DatagramPacket dp = new DatagramPacket(buf,buf.length,InetAddress.getByName(txtIP.getText()),sendPort);

}

catch(Exception ex)

{

ex.printStackTrace();

}

txtMSG.setText("");//清空消息框

txtMSG.requestFocus();

}

}

}

jsp網(wǎng)頁(yè)怎么實(shí)現(xiàn)即時(shí)聊天

jsp中可以實(shí)現(xiàn)簡(jiǎn)單的聊天功能,例子如下:

chat.jsp代碼如下:

%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%

%@ page language="java" contentType="text/html;charset=GB2312"%

html

body

%

try{

request.setCharacterEncoding("GB2312");

String mywords=request.getParameter("message");

String t="";

if(application.getAttribute("words")==null mywords!=null){

t= (String)request.getRemoteAddr() + ":" + mywords + "br/";

application.setAttribute("words",(Object)t);

out.println(t);

}

else if(mywords!=null){

t=(String)application.getAttribute("words");

t += (String)request.getRemoteAddr() + ":" + mywords + "br/";

application.setAttribute("words",(Object)t);

out.println(t);

}

}

catch(Exception e){

}

%

form method="post" action="index.jsp"

input name="message" type="text" size=50

input type="submit" value="發(fā)送消息"

/form

/body/html

輸出對(duì)話內(nèi)容如下:

Java網(wǎng)頁(yè)聊天如何實(shí)現(xiàn),問(wèn)題如下:

改成下面的樣子:

%@ page language="java" pageEncoding="GBK"%

html

head

titleMy JSP 'lab.jsp' starting page/title

/head

body

%

if(application.getAttribute("chat")!=null)

{ if(request.getParameter("mywords")!=null)

{ String mywords=request.getParameter("mywords");

mywords=(String)application.getAttribute("chat")+"br"+mywords;

application.setAttribute("chat",mywords);

out.print((String)application.getAttribute("chat"));

}

}else{

application.setAttribute("chat","");

}

%

form action="a1.jsf" method="post"

input type="text" size="30" name="mywords" value="我喜歡聊天"

input type="submit" name="sumbit" value="提交"

/form

/body

/html

1.要用post提交,否則中文亂碼

2.out.print((String)application.getAttribute("char")); 這句你寫(xiě)錯(cuò)了,應(yīng)該是chat不是char

3.你第一次運(yùn)行的時(shí)候application.getAttribute("chat")肯定是空的,是空的話你又什么都不作,下次還是空的呀

本文名稱:java網(wǎng)頁(yè)聊天代碼,javaweb在線聊天系統(tǒng)
網(wǎng)頁(yè)地址:http://aaarwkj.com/article40/hsojeo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)做網(wǎng)站、網(wǎng)站策劃自適應(yīng)網(wǎng)站、網(wǎng)站收錄、軟件開(kāi)發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名
午夜精品视频免费91| 麻豆视传媒短视频免费看| 91在线看片国产免费观看| 熟妇女人妻丰满少妇中文| 中文字幕在线看二区不卡| 综合激情四射亚洲激情| 日本国产一区二区三区在线| av永久天堂一区二区三区| 国产精品欧美日韩一区| 久久香蕉精品国产亚洲av| 禁止18岁以下观看的视频| 香蕉视频欧美久久精品| 国产精品亚洲二区三区三州| 日韩人妻精品中文字幕专区不卡| 青青成线在人线免费啪| 亚洲熟女内射特写一区| 一区二区三区欧美黑人| 青青草针对华人在线视频| 九九蜜桃视频香蕉视频| 欧美人妻不卡一区二区久久| 亚洲日本不卡在线一区二区| 国产欧美日韩精品三级| 日本精品女优一区二区三区四区 | 国产男女猛烈无遮挡网站| 亚洲偷拍自拍在线观看| 饥渴少妇高潮特殊按摩| 日本免费中文字幕在线| 日韩av黄色大片在线播看| 亚洲精品一区二区播放| 欧美两性色一区二区三区| 熟女人妻视频一区二区| 男女啪啪国产精品视频| 国产成人精品亚洲日本片| 91国产熟女自拍视频| 男女午夜激情啪啪视频| 国产美女高潮流白浆视频免费看 | 久久精品国产免费夜夜嗨| 麻豆国产原创av色哟哟| 伊人婷婷综合激情网| 国产成人综合亚洲国产| 久久精品国产亚洲av高清观看|