恕我愚昧.......百度的看不懂......这是js
var ws, name, client_list={};
var time_prev;
var time_this;// 连接服务端
function connect() {
   ws = new WebSocket("ws://"+document.domain+":8282");   // 创建websocket
   ws.onopen = onopen;   // 当socket连接打开时,输入用户名
   ws.onmessage = onmessage;  // 当有消息时根据消息类型显示不同信息
   ws.onclose = function() {
  console.log("连接关闭,定时重连");
  connect();
   };
   ws.onerror = function() {
  console.log("出现错误");
   };
}// 连接建立时发送登录信息
function onopen() {
var login_data = '{"type":"login","client_name":"'+user_name+'","room_id":"'+room_id+'"}';
ws.send(login_data);
}// 服务端发来消息时
function onmessage(e){
    // console.log(e.data);
    // json数据转换成js对象
    var data = eval("("+e.data+")");
    var type = data.type || '';
if(type == "init"){
// 利用jquery发起ajax请求,将client_id发给后端进行uid绑定
        $.post('/index/house/bind.html', {room_id: room_id ,client_id: data.client_id}, function(data){}, 'json');
}
if(type == "error"){
alert(data.info);
}
if(type == "newgame"){
window.location.reload();
}
if(type == "meone"){
document.getElementById("coins").innerText = data.coins;
}
if(type == "reone"){
var element=document.getElementsByClassName("mui-control-item").item(0);
//--------------错层
if(data['house_id'] != house_id)window.location.reload();
if(data['plies'] != element.id){
time_prev=new Date().getTime();
curr_plies=data['plies']-1;
delay_load_house();
}

//--------------拆楼
element.className="mui-selected";
element.innerHTML=data['price'];
$(element).fadeOut(1000);
setTimeout(function(){
$("#house p").first().remove();
},1000);

//--------------加楼
row=$("#house p").last().attr("id");
if(row>1){
addrow=row-1;
price=get_prize(addrow);
if(price>=5){
classname="hide mui-control-item big";
txt=price;
}else{
classname="hide mui-control-item";
txt=addrow+'层';
}
$("#house").append('<p class="'+classname+'" id="'+addrow+'">'+txt+'</p>');
$("#house .hide").slideDown(1000);
}
}
};界面
package com.background;import java.awt.event.*;
import java.io.FileNotFoundException;
import javax.swing.*;
import com.background.method.Backmusic;
import javax.script.ScriptException;   /**  * 直接调用js代码  */
import javax.script.ScriptEngine; 
import javax.script.ScriptEngineManager;
public class XMB extends JFrame implements ActionListener {
/**
 * 主程序
 */
private static final long serialVersionUID = 3818096835674246069L;
House lou;
static Backmusic music;
public XMB() throws FileNotFoundException{
setTitle("拆楼游戏");
setSize(768,1366);
setResizable(false);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setUndecorated(true);// 取消窗体修饰效果
lou=new House();
lou.setLayout(null);
add(lou);
Timer timer=new Timer(50,this);//移动方法
timer.start();
setVisible(true);
//播放音乐
music = new Backmusic("music/maomi.mp3");
music.play();  } public static void main(String[] args)  throws Exception  {
new XMB();
} public void actionPerformed(ActionEvent e) {
lou.bird.niao(); 
lou.bird.yun();
lou.bird.yun2();
lou.repaint();
} /*
 * public void run() { try { Thread.sleep(20000); setVisible(false);
 * //player.stop(); System.exit(0); //System.exit(0); } catch
 * (InterruptedException e) { e.printStackTrace(); } }
 */
}
---------------
package com.background;import java.awt.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
import javax.swing.*;import com.database.MyDBManger;
import com.background.method.Method;
import com.database.house_item;public class House extends JPanel { Connection connection = null ; 
ResultSet rs = null ;
Statement statement = null ; 
static JFrame frame = new JFrame();
//static BaseDao bd = new BaseDao();
static house_item h = new house_item();
/**
 * 控件 
 */
private static final long serialVersionUID = 1L;
public Method bird=new Method();
@Override
public void paint(Graphics g){
super.paint(g);
//Random random = new Random(500);
//Image img;
//背景
ImageIcon bj = new ImageIcon("images/bg.jpg");
g.drawImage(bj.getImage(),0, 0, 768, 1366,this);
//云 
ImageIcon y1 = new ImageIcon("images/cloud1.png");
g.drawImage(y1.getImage(),bird.y,300, 300, 200, this);
ImageIcon y2 = new ImageIcon("images/cloud3.png");
g.drawImage(y2.getImage(),bird.y2,300, 300, 200, this); //楼层
// try {
// connection = MyDBManger.getDBManger().getconnection();
// statement = connection.createStatement();
// rs = statement.executeQuery("select * from house_item where plies");
// for (int i = 212; i<=1340 ; i++) {
// while(rs.next()) {
// for(int j=245;j<=1340;j--) {
// ImageIcon lou = new ImageIcon("images/lou.png");
// g.drawImage(lou.getImage(),280, i, 200, 52,this);
// g.setFont(new Font("宋体", Font.BOLD, 12));
// g.setColor(Color.black);
// g.drawString(rs.getInt("Plies")+"层", 358, j);
// j=j+44;
// }
//
// }
// i=i+42;
// }
// }catch (Exception e) {
// e.printStackTrace();
// }finally{
// System.out.println("数据库数据成功获取!!");
// } //小鸟
ImageIcon n = new ImageIcon(bird.imgs[bird.index]);
g.drawImage(n.getImage(),bird.x, 700, 60, 60, this);
//街道
ImageIcon jd = new ImageIcon("images/bg_bottom.png");
g.drawImage(jd.getImage(), 0,1310,768, 50, this);
//炮台
ImageIcon pt = new ImageIcon("images/button.png");
g.drawImage(pt.getImage(), 340,1280, 80, 80, this); //总榜
ImageIcon zb = new ImageIcon("images/zb.png");
g.drawImage(zb.getImage(),10, 20, 230, 400,this); //日榜
ImageIcon lts2 = new ImageIcon("images/rb.png");
g.drawImage(lts2.getImage(),530, 820, 230, 600,this); //超级大奖
ImageIcon sp = new ImageIcon("images/sp.png");
g.drawImage(sp.getImage(),10, 420, 230, 350,this); //超级大奖
ImageIcon hp = new ImageIcon("images/hp.png");
g.drawImage(hp.getImage(),530, 420, 230, 350,this); //聊天室
ImageIcon lts = new ImageIcon("images/lts.png");
g.drawImage(lts.getImage(),10, 820, 230, 600,this); }
}