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

2014-11-24 03:14:15 · 作者: · 浏览: 6
t("%tF %

updateDateLabel.setText(dateStr);

final GridBagConstraints updateDateLayout = new GridBagConstraints();

updateDateLayout.gridy = 2;

updateDateLayout.gridx = 0;

sysUpdatePanel.add(updateDateLabel, updateDateLayout);

final JLabel updateStaticLabel = new JLabel("更新状态:");

final GridBagConstraints updateStaticLayout = new GridBagConstraints();

updateStaticLayout.gridy = 3;

updateStaticLayout.gridx = 0;

sysUpdatePanel.add(updateStaticLabel, updateStaticLayout);

final JLabel updateInfoLabel = new JLabel();// 版本信息标签

checkSysInfo(updateInfoLabel);// 调用检测版本更新的方法

final GridBagConstraints gridBagConstraints_5 = new GridBagConstraints();

gridBagConstraints_5.gridy = 4;

gridBagConstraints_5.gridx = 0;

sysUpdatePanel.add(updateInfoLabel, gridBagConstraints_5);

JPanel statePanel = new JPanel();

add(statePanel, BorderLayout.SOUTH);

statePanel.setLayout(new BorderLayout());

statePanel.add(stateLabel);

stateLabel.setText("总人数:" + chatTree.getRowCount());

return sysToolScrollPanel;

}

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

private void initUserInfoButton(){

try{

String ip = InetAddress.getLocalHost().getHostAddress();

User user = dao.getUser(ip);

userInfoButton.setIcon(user.getIconImg());

userInfoButton.setText(user.getName());

userInfoButton.setIconTextGap(JLabel.RIGHT);

userInfoButton.setToolTipText(user.getTipText());

userInfoButton.getParent().doLayout();

}catch(UnknownHostException e1){

e1.printStackTrace();

}

}

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

private void showMessageBar(){// 显示公告信息按钮的线程

new Thread(new Runnable() {

public void run() {

while (true) {

if (!messageStack.empty()) {

try {

messageAlertButton.setIcon(messageAlertNullIcon);

messageAlertButton.setPreferredSize(new Dimension(20, 20));

Thread.sleep(500);

messageAlertButton.setIcon(messageAlertIcon);

Thread.sleep(500);

} catch (InterruptedException e) {

e.printStackTrace();

}

} else {

try {

Thread.sleep(3000);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

}

}).start();

}

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

private void checkSysInfo(final JLabel updateInfo){

new Thread(new Runnable(){

public void run(){

String info = "";

while(true){

try{

netFilePath = preferences.get("updatePath", "EQ.jar");

if(netFilePath.equals("EQ.jar")){

info = "<html>

无法登录
未设置升级路径
";

updateInfo.setText(info);

continue;

}

netFile = new File(netFilePath);

if(netFile.exists()){

Date netDate = new Date(netFile.lastModified());

if(!localFile.exists()){

info = "本地程序位置出错!";

}else{

Date localDate = new Date(localFile.lastModified());

if(netDate.after(localDate)){

info = "网络上有最新程序!";

pushMessage(info);

}else{

info = "现在是最新程序!";

}

}

}else{

info = "

无法访问
升级路径
";

}

updateInfo.setText(info);

Thread.sleep(5*1000);

}catch(InterruptedException e){

e.printStackTrace();

}

}

}

}).start();

}

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

class SearchUserActionListener implements ActionListener{

private final JList list;

SearchUserActionListener(JList list){

this.list = list;

}

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

if(searchUserButton.isSelected()){

searchUserButton.setText("停止搜索");

new Thread(new Runnable(){

public void run(){

Resource.searchUsers(chatTree, progressBar,list, searchUserButton);

}

}).start();

}else{

searchUserButton.setText("搜索新用户");

}

}

}

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

class SysSetPanelOKListener implements ActionListener{

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

String command = e.getActionCommand();

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

String updatePath = updatePathTField.getText();

String placardPath = placardPathTField.getText();

String pubPath = pubPathTField.getText();

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

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

preferences.put("pubPath", pubPath); // 设置公共程序路径

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

}

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

String username = userNameTField.getText();

String password = new String(passwordTFiel