小程序實現聊天
❶ 微信小程序可以做即使聊天嗎
可以的,現在下程序已經開通了客服功能,很多商家已經在用了。
❷ java聊天小程序
汗,LZ真是牛,這可不是一個小程序,怎麼可能全部代碼貼出來,也沒工夫寫額,以前在學校我做過,我把我的思路給你好了,首先寫出服務端和客戶端,多線程實現收發,支持點對點聊天,如果這些LZ不會,那就先去看看基礎吧,在此基礎上,創建登錄用戶類,有用戶ID(String),昵稱和socket屬性,一個房間管理類,用來管理私聊,群聊或者2個以上人的聊天,有一個MAP屬性,以聊天者ID相加的值為建,以保存所有聊天者socket的List為值,其中群聊是MAP的默認屬性,登陸一個用戶,value就添加他socket,當用戶選擇一個人私聊,或者幾個人群聊時,MAP創建相應的映射,就這樣了,當時我是全部實現了,但在關閉socket時有些問題。
具體邏輯和其中BUG,自己調和寫吧,例如用ID相加為建有時會有問題。
❸ 微信小程序能不能做社交聊天功能
微信小程序目前可以做簡單的社交聊天功能的。
目前已經有一些社交的軟體出現了。
❹ 求一JAVA 聊天小程序使用圖形用戶界面。能實現一個聊天室中多人聊天。可以兩人私聊。可以更改字體和顏色。
服務端代碼如下:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.net.*;
import java.io.*;
/*
* 聊天服務端的主框架類
*/
public class ChatServer extends JFrame implements ActionListener{
public static int port = 8888;//服務端的偵聽埠
ServerSocket serverSocket;//服務端Socket
Image icon;//程序圖標
JComboBox combobox;//選擇發送消息的接受者
JTextArea messageShow;//服務端的信息顯示
JScrollPane messageScrollPane;//信息顯示的滾動條
JTextField showStatus;//顯示用戶連接狀態
JLabel sendToLabel,messageLabel;
JTextField sysMessage;//服務端消息的發送
JButton sysMessageButton;//服務端消息的發送按鈕
UserLinkList userLinkList;//用戶鏈表
//建立菜單欄
JMenuBar jMenuBar = new JMenuBar();
//建立菜單組
JMenu serviceMenu = new JMenu ("服務(V)");
//建立菜單項
JMenuItem portItem = new JMenuItem ("埠設置(P)");
JMenuItem startItem = new JMenuItem ("啟動服務(S)");
JMenuItem stopItem=new JMenuItem ("停止服務(T)");
JMenuItem exitItem=new JMenuItem ("退出(X)");
JMenu helpMenu=new JMenu ("幫助(H)");
JMenuItem helpItem=new JMenuItem ("幫助(H)");
//建立工具欄
JToolBar toolBar = new JToolBar();
//建立工具欄中的按鈕組件
JButton portSet;//啟動服務端偵聽
JButton startServer;//啟動服務端偵聽
JButton stopServer;//關閉服務端偵聽
JButton exitButton;//退出按鈕
//框架的大小
Dimension faceSize = new Dimension(400, 600);
ServerListen listenThread;
JPanel downPanel ;
GridBagLayout girdBag;
GridBagConstraints girdBagCon;
/**
* 服務端構造函數
*/
public ChatServer(){
init();//初始化程序
//添加框架的關閉事件處理
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.pack();
//設置框架的大小
this.setSize(faceSize);
//設置運行時窗口的位置
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation( (int) (screenSize.width - faceSize.getWidth()) / 2,
(int) (screenSize.height - faceSize.getHeight()) / 2);
this.setResizable(false);
this.setTitle("聊天室服務端"); //設置標題
//程序圖標
icon = getImage("icon.gif");
this.setIconImage(icon); //設置程序圖標
show();
//為服務菜單欄設置熱鍵'V'
serviceMenu.setMnemonic('V');
//為埠設置快捷鍵為ctrl+p
portItem.setMnemonic ('P');
portItem.setAccelerator (KeyStroke.getKeyStroke (KeyEvent.VK_P,InputEvent.CTRL_MASK));
//為啟動服務快捷鍵為ctrl+s
startItem.setMnemonic ('S');
startItem.setAccelerator (KeyStroke.getKeyStroke (KeyEvent.VK_S,InputEvent.CTRL_MASK));
//為埠設置快捷鍵為ctrl+T
stopItem.setMnemonic ('T');
stopItem.setAccelerator (KeyStroke.getKeyStroke (KeyEvent.VK_T,InputEvent.CTRL_MASK));
//為退出設置快捷鍵為ctrl+x
exitItem.setMnemonic ('X');
exitItem.setAccelerator (KeyStroke.getKeyStroke (KeyEvent.VK_X,InputEvent.CTRL_MASK));
//為幫助菜單欄設置熱鍵'H'
helpMenu.setMnemonic('H');
//為幫助設置快捷鍵為ctrl+p
helpItem.setMnemonic ('H');
helpItem.setAccelerator (KeyStroke.getKeyStroke (KeyEvent.VK_H,InputEvent.CTRL_MASK));
}
/**
* 程序初始化函數
*/
public void init(){
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
//添加菜單欄
serviceMenu.add (portItem);
serviceMenu.add (startItem);
serviceMenu.add (stopItem);
serviceMenu.add (exitItem);
jMenuBar.add (serviceMenu);
helpMenu.add (helpItem);
jMenuBar.add (helpMenu);
setJMenuBar (jMenuBar);
//初始化按鈕
portSet = new JButton("埠設置");
startServer = new JButton("啟動服務");
stopServer = new JButton("停止服務" );
exitButton = new JButton("退出" );
//將按鈕添加到工具欄
toolBar.add(portSet);
toolBar.addSeparator();//添加分隔欄
toolBar.add(startServer);
toolBar.add(stopServer);
toolBar.addSeparator();//添加分隔欄
toolBar.add(exitButton);
contentPane.add(toolBar,BorderLayout.NORTH);
//初始時,令停止服務按鈕不可用
stopServer.setEnabled(false);
stopItem .setEnabled(false);
//為菜單欄添加事件監聽
portItem.addActionListener(this);
startItem.addActionListener(this);
stopItem.addActionListener(this);
exitItem.addActionListener(this);
helpItem.addActionListener(this);
//添加按鈕的事件偵聽
portSet.addActionListener(this);
startServer.addActionListener(this);
stopServer.addActionListener(this);
exitButton.addActionListener(this);
combobox = new JComboBox();
combobox.insertItemAt("所有人",0);
combobox.setSelectedIndex(0);
messageShow = new JTextArea();
messageShow.setEditable(false);
//添加滾動條
messageScrollPane = new JScrollPane(messageShow,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
messageScrollPane.setPreferredSize(new Dimension(400,400));
messageScrollPane.revalidate();
showStatus = new JTextField(35);
showStatus.setEditable(false);
sysMessage = new JTextField(24);
sysMessage.setEnabled(false);
sysMessageButton = new JButton();
sysMessageButton.setText("發送");
//添加系統消息的事件偵聽
sysMessage.addActionListener(this);
sysMessageButton.addActionListener(this);
sendToLabel = new JLabel("發送至:");
messageLabel = new JLabel("發送消息:");
downPanel = new JPanel();
girdBag = new GridBagLayout();
downPanel.setLayout(girdBag);
girdBagCon = new GridBagConstraints();
girdBagCon.gridx = 0;
girdBagCon.gridy = 0;
girdBagCon.gridwidth = 3;
girdBagCon.gridheight = 2;
girdBagCon.ipadx = 5;
girdBagCon.ipady = 5;
JLabel none = new JLabel(" ");
girdBag.setConstraints(none,girdBagCon);
downPanel.add(none);
girdBagCon = new GridBagConstraints();
girdBagCon.gridx = 0;
girdBagCon.gridy = 2;
girdBagCon.insets = new Insets(1,0,0,0);
girdBagCon.ipadx = 5;
girdBagCon.ipady = 5;
girdBag.setConstraints(sendToLabel,girdBagCon);
downPanel.add(sendToLabel);
girdBagCon = new GridBagConstraints();
girdBagCon.gridx =1;
girdBagCon.gridy = 2;
girdBagCon.anchor = GridBagConstraints.LINE_START;
girdBag.setConstraints(combobox,girdBagCon);
downPanel.add(combobox);
girdBagCon = new GridBagConstraints();
girdBagCon.gridx = 0;
girdBagCon.gridy = 3;
girdBag.setConstraints(messageLabel,girdBagCon);
downPanel.add(messageLabel);
girdBagCon = new GridBagConstraints();
girdBagCon.gridx = 1;
girdBagCon.gridy = 3;
girdBag.setConstraints(sysMessage,girdBagCon);
downPanel.add(sysMessage);
girdBagCon = new GridBagConstraints();
girdBagCon.gridx = 2;
girdBagCon.gridy = 3;
girdBag.setConstraints(sysMessageButton,girdBagCon);
downPanel.add(sysMessageButton);
girdBagCon = new GridBagConstraints();
girdBagCon.gridx = 0;
girdBagCon.gridy = 4;
girdBagCon.gridwidth = 3;
girdBag.setConstraints(showStatus,girdBagCon);
downPanel.add(showStatus);
contentPane.add(messageScrollPane,BorderLayout.CENTER);
contentPane.add(downPanel,BorderLayout.SOUTH);
//關閉程序時的操作
this.addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
stopService();
System.exit(0);
}
}
);
}
/**
* 事件處理
*/
public void actionPerformed(ActionEvent e) {
Object obj = e.getSource();
if (obj == startServer || obj == startItem) { //啟動服務端
startService();
}
else if (obj == stopServer || obj == stopItem) { //停止服務端
int j=JOptionPane.showConfirmDialog(
this,"真的停止服務嗎?","停止服務",
JOptionPane.YES_OPTION,JOptionPane.QUESTION_MESSAGE);
if (j == JOptionPane.YES_OPTION){
stopService();
}
}
else if (obj == portSet || obj == portItem) { //埠設置
//調出埠設置的對話框
PortConf portConf = new PortConf(this);
portConf.show();
}
else if (obj == exitButton || obj == exitItem) { //退出程序
int j=JOptionPane.showConfirmDialog(
this,"真的要退出嗎?","退出",
JOptionPane.YES_OPTION,JOptionPane.QUESTION_MESSAGE);
if (j == JOptionPane.YES_OPTION){
stopService();
System.exit(0);
}
}
else if (obj == helpItem) { //菜單欄中的幫助
//調出幫助對話框
Help helpDialog = new Help(this);
helpDialog.show();
}
else if (obj == sysMessage || obj == sysMessageButton) { //發送系統消息
sendSystemMessage();
}
}
/**
* 啟動服務端
*/
public void startService(){
try{
serverSocket = new ServerSocket(port,10);
messageShow.append("服務端已經啟動,在"+port+"埠偵聽...\n");
startServer.setEnabled(false);
startItem.setEnabled(false);
portSet.setEnabled(false);
portItem.setEnabled(false);
stopServer .setEnabled(true);
stopItem .setEnabled(true);
sysMessage.setEnabled(true);
}
catch (Exception e){
//System.out.println(e);
}
userLinkList = new UserLinkList();
listenThread = new ServerListen(serverSocket,combobox,
messageShow,showStatus,userLinkList);
listenThread.start();
}
/**
* 關閉服務端
*/
public void stopService(){
try{
//向所有人發送伺服器關閉的消息
sendStopToAll();
listenThread.isStop = true;
serverSocket.close();
int count = userLinkList.getCount();
int i =0;
while( i < count){
Node node = userLinkList.findUser(i);
node.input .close();
node.output.close();
node.socket.close();
i ++;
}
stopServer .setEnabled(false);
stopItem .setEnabled(false);
startServer.setEnabled(true);
startItem.setEnabled(true);
portSet.setEnabled(true);
portItem.setEnabled(true);
sysMessage.setEnabled(false);
messageShow.append("服務端已經關閉\n");
combobox.removeAllItems();
combobox.addItem("所有人");
}
catch(Exception e){
//System.out.println(e);
}
}
/**
* 向所有人發送伺服器關閉的消息
*/
public void sendStopToAll(){
int count = userLinkList.getCount();
int i = 0;
while(i < count){
Node node = userLinkList.findUser(i);
if(node == null) {
i ++;
continue;
}
try{
node.output.writeObject("服務關閉");
node.output.flush();
}
catch (Exception e){
//System.out.println("$$$"+e);
}
i++;
}
}
/**
* 向所有人發送消息
*/
public void sendMsgToAll(String msg){
int count = userLinkList.getCount();//用戶總數
int i = 0;
while(i < count){
Node node = userLinkList.findUser(i);
if(node == null) {
i ++;
continue;
}
try{
node.output.writeObject("系統信息");
node.output.flush();
node.output.writeObject(msg);
node.output.flush();
}
catch (Exception e){
//System.out.println("@@@"+e);
}
i++;
}
sysMessage.setText("");
}
/**
* 向客戶端用戶發送消息
*/
public void sendSystemMessage(){
String toSomebody = combobox.getSelectedItem().toString();
String message = sysMessage.getText() + "\n";
messageShow.append(message);
//向所有人發送消息
if(toSomebody.equalsIgnoreCase("所有人")){
sendMsgToAll(message);
}
else{
//向某個用戶發送消息
Node node = userLinkList.findUser(toSomebody);
try{
node.output.writeObject("系統信息");
node.output.flush();
node.output.writeObject(message);
node.output.flush();
}
catch(Exception e){
//System.out.println("!!!"+e);
}
sysMessage.setText("");//將發送消息欄的消息清空
}
}
/**
* 通過給定的文件名獲得圖像
*/
Image getImage(String filename) {
URLClassLoader urlLoader = (URLClassLoader)this.getClass().
getClassLoader();
URL url = null;
Image image = null;
url = urlLoader.findResource(filename);
image = Toolkit.getDefaultToolkit().getImage(url);
MediaTracker mediatracker = new MediaTracker(this);
try {
mediatracker.addImage(image, 0);
mediatracker.waitForID(0);
}
catch (InterruptedException _ex) {
image = null;
}
if (mediatracker.isErrorID(0)) {
image = null;
}
return image;
}
public static void main(String[] args) {
ChatServer app = new ChatServer();
}
}
❺ 如何用java做一個聊天小程序 要求使用圖形用戶界面,可以實現一個聊天室中多人聊天,也可以兩人私聊
給個地址,我Email你
❻ 微信小程序 實現聊天功能的 核心代碼是什麼
保密性 完備性 可用性。
定義
國際標准化委員會的定義是"為數據處理系統和採取的技術的和管理的安全保護,保護計算機硬體、軟體、數據不因偶然的或惡意的原因而遭到破壞、更改、顯露。"
中國公安部計算機管理監察司的定義是"計算機安全是指計算機資產安全,即計算機信息系統資源和信息資源不受自然和人為有害因素的威脅和危害。"
❼ 如何用java做一個聊天小程序 要求使用圖形用戶界面,可以實現一個聊天室中多人聊天,也可以兩人私聊,
openfire
smack
spark
搜索一下
實現起來比較簡單
❽ 微信小程序可以做聊天室嗎
可以啊,你可以嘗試。但是微信小程序比較適合線下,沒有線下資源最好認真考慮