
2.登陆
3.房间选择和聊天页面
。用户先到1页面注册账号,然后到2登陆聊天室,再到3页面加入一个已经创建的房间,开始聊天。具体做就麻烦了,我以前做这个玩意花了2天。有个技术难点要克服,a在他的聊天页面上说了一句话,b的聊天页面必须立刻把这句话显示出来。可以这么做,a说话了,他点了提交按钮,那么一个请求被提交到后台的servlet或者action,后台知道a说了一句话,于是,把全局变量(例如application里)messagearrived的值设置为true,聊天页面有段javascript代码,每隔一小段时间(如0.2秒)检查messagearrived的值,发现messagearrived==true,就刷新页面(页面刷新时,a说的话就显示出来了),然后再把messagearrived设回false。这样聊天记录能实时地显示。因为每个人说话,都会导致整个页面刷新,所以这个聊天室给人的感觉是,页面一卡一卡的,不正常。ajax用上以后,不会有整个页面老刷新的现象了,给用户的感觉很好。
将以下代码保存为 Test.java 即可运行(界面挫了点,不过核心功能都有,你可以自己拿回去改改界面就可以了)package com
import javax.swing.*
import java.awt.BorderLayout
import java.awt.event.ActionListener
import java.awt.event.ActionEvent
public class Test extends JFrame{
public static void main(String args[]){
new Test()
}
JTextField ieField
JButton button
public Test(){
super("单击按钮打开一个网页")
ieField = new JTextField("www.sina.com",30)
button = new JButton("打开 IE 网页")
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
try{
Process process = Runtime.getRuntime().exec("cmd.exe /C start iexplore " + ieField.getText())
}catch(Exception e){
e.printStackTrace()
}
}
})
this.getContentPane().setLayout( new BorderLayout())
this.getContentPane().add(ieField,BorderLayout.CENTER)
this.getContentPane().add(button,BorderLayout.SOUTH)
this.setSize(600,200)
this.setVisible(true)
}
}
散分吧 赚点小分真不容易....
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)