仿QQ聊天软件及源码java版(八)

2014-11-24 03:14:15 · 作者: · 浏览: 10
d.getPassword());

preferences.put("username", username); // 设置系统升级路径

preferences.put("password", password);// 设置系统公告路径

JOptionPane.showMessageDialog(EQ.this, "登录设置保存完毕");

}

if (command.equals("ipOK")) {

String ipStart = ipStartTField.getText();

String ipEnd = ipEndTField.getText();

try {

InetAddress.getByName(ipStart);

InetAddress.getByName(ipEnd);

} catch (UnknownHostException e1) {

JOptionPane.showMessageDialog(EQ.this, "IP地址格式错误");

return;

}

preferences.put("ipStart", ipStart); // 设置系统升级路径

preferences.put("ipEnd", ipEnd);// 设置系统公告路径

JOptionPane.showMessageDialog(EQ.this, "IP设置保存完毕");

}

}

}

//----------------------------------------------------------------------------------

private final class SysUpdateListener implements ActionListener{// 系统更新事件

@Override

public void actionPerformed(final ActionEvent e) {

// TODO Auto-generated method stub

String username = preferences.get("username", null);

String password = preferences.get("password", null);

if(username == null || password == null){

pushMessage("未设置登录升级服务器的用户名或密码");

return;

}

Resource.loginPublic(username, password);

updateProject();

}

}

//----------------------------------------------------------------------------------

private class ChatTreeMouseListener extends MouseAdapter{// 用户列表的监听器

public void mouseClicked(final MouseEvent e){

if (e.getClickCount() == 2) {

TreePath path = chatTree.getSelectionPath();

if (path == null)

return;

DefaultMutableTreeNode node = (DefaultMutableTreeNode) path

.getLastPathComponent();

User user = (User) node.getUserObject();

try {

TelFrame.getInstance(ss, new DatagramPacket(new byte[0], 0,

InetAddress.getByName(user.getIp()), 1111),

chatTree);

} catch (IOException e1) {

e1.printStackTrace();

}

}

}

}

//----------------------------------------------------------------------------------

private void server(){// 服务器启动方法

new Thread(new Runnable(){

public void run(){

while(true){

if(ss != null){

byte[] buf = new byte[4096];

DatagramPacket dp = new DatagramPacket(buf,buf.length);

try{

ss.receive(dp);

}catch(IOException e){

e.printStackTrace();

}

TelFrame.getInstance(ss,d