- 浏览: 5381 次
- 性别:
最新评论
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.Rectangle;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.TrayIcon.MessageType;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.Scanner;
import java.util.Stack;
import java.util.prefs.Preferences;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JPopupMenu;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.JToggleButton;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
public class EQ extends JDialog{
private JTextField ipEndTField;
private JTextField ipStartTField;
private JTextField userNameTField;//用户框
private JPasswordField passwordTField;//密码框
private JTextField placardPathTField;//placard:公告
private JTextField updatePathTField;//更新路径
private JTextField pubPathTField;
public static EQ frame = null;
private ChatTree chatTree;
private JPopupMenu popupMenu;//右键菜单
private JTabbedPane tabbedPane;//分页面板
private JToggleButton searchUserButton;//搜索用户按钮
private JProgressBar progressBar;//滚动条
private JList faceList;
private JButton selectInterfaceOKButton;
private DatagramSocket ss;//数据报插座
private final JLabel stateLabel;
private static String user_dir;
private static File localFile;
private static File netFile;
private String netFilePath;
private JButton messageAlertButton;
private Stack<String> messageStack;////Stack 类表示后进先出(LIFO)的对象堆栈。
private ImageIcon messageAlertIcon;
private ImageIcon messageAlertNullIcon;
private Rectangle location;
public static TrayIcon trayicon;
private Dao dao;
//Preferences.systeRoot:返回系统的根首选项节点 Preferences:参数选择
public final static Preferences preferences = Preferences.systemRoot();
private JButton userInfoButton;
//----------------------------------------------------------------------------------
public static void main(String[] args){
try{
String laf = preferences.get("lookAndFeel", "java默认");
if(laf.indexOf("当前系统") > -1){
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
EQ frame = new EQ();
frame.setVisible(true);
frame.SystemTrayInitial();// 初始化系统栏
frame.server();
frame.checkPlacard();
}catch(Exception e){
e.printStackTrace();
}
}
//----------------------------------------------------------------------------------
public EQ(){
super(new JFrame());
frame = this;
dao = Dao.getDao();
location = dao.getLocation();
setTitle("EQ聊天");
setBounds(location);
progressBar = new JProgressBar();
//BevelBorder:该类实现简单的双线斜面边框。Bevel:斜面 lowered:凹入斜面类型。
progressBar.setBorder(new BevelBorder(BevelBorder.LOWERED));
tabbedPane = new JTabbedPane();
popupMenu = new JPopupMenu();
chatTree = new ChatTree(this);
user_dir = System.getProperty("user.dir");// 程序执行路径用于系统更新
localFile = new File(user_dir + File.separator + "EQ.jar");// 本地EQ文件
stateLabel = new JLabel();// 状态栏标签
this.addWindowListener(new FrameWindowListener());// 添加窗体监视器
this.addComponentListener(new ComponentAdapter(){
public void componentResized(final ComponentEvent e){
saveLocation();
}
public void componentMoved(final ComponentEvent e){
saveLocation();
}
});
try{// 启动通讯服务端口
ss = new DatagramSocket(1111);
}catch(SocketException e2){
if(e2.getMessage().startsWith("Address already in use")){
showMessageDialog("服务端口被占用,或者本软件已经运行。");
}
System.exit(0);
}
{// 初始化公共信息按钮
messageAlertIcon = new ImageIcon(EQ.class.getResource("/image/messageAlert.gif"));
messageAlertNullIcon = new ImageIcon(EQ.class.getResource("/image/messageAlertNull20.gif"));
messageStack = new Stack<String>();
messageAlertButton = new JButton();
messageAlertButton.setHorizontalAlignment(SwingConstants.RIGHT);
messageAlertButton.setContentAreaFilled(false);//不填充内容区域
final JPanel BannerPanel = new JPanel();
BannerPanel.setLayout(new BorderLayout());
this.add(BannerPanel,BorderLayout.NORTH);
userInfoButton = new JButton();
BannerPanel.add(userInfoButton,BorderLayout.WEST);
userInfoButton.setMargin(new Insets(0,0,0,10));//Margin:边距 insets:插入
initUserInfoButton();// 初始化本地用户头像按钮
BannerPanel.add(messageAlertButton,BorderLayout.CENTER);
messageAlertButton.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent arg0) {
if(!messageStack.empty()){
showMessageDialog(messageStack.pop());//堆栈顶部的对象(Vector 对象中的最后一项)。
}
}
});
messageAlertButton.setIcon(messageAlertIcon);
showMessageBar();
}
this.add(tabbedPane,BorderLayout.CENTER);
tabbedPane.setTabPlacement(SwingConstants.LEFT);//设置此选项卡窗格的选项卡布局
ImageIcon userTicon = new ImageIcon(EQ.class.getResource("/image/tabIcon/tabLeft.PNG"));
tabbedPane.addTab(null,userTicon,createUserList(),"用户列表");
ImageIcon sysOTicon = new ImageIcon(EQ.class.getResource("/image/tabIcon/tabLeft2.PNG"));
tabbedPane.addTab(null, sysOTicon, createSysToolPanel(), "系统操作");
ImageIcon sysSTicon = new ImageIcon(EQ.class.getResource("/image/tabIcon/tabLeft3.png"));
tabbedPane.addTab(null, sysSTicon, createSysSetPanel(), "系统设置");
this.setAlwaysOnTop(true);//总在顶部
}
//----------------------------------------------------------------------------------
private JScrollPane createSysSetPanel(){//系统设置面板
final JPanel sysSetPanel = new JPanel();
JScrollPane scrollPane = new JScrollPane(sysSetPanel);
sysSetPanel.setLayout(new BoxLayout(sysSetPanel,BoxLayout.Y_AXIS));
scrollPane.setBorder(new EmptyBorder(0,0,0,0));
final JPanel sysPathPanel = new JPanel();
sysPathPanel.setMaximumSize(new Dimension(600,200));
sysPathPanel.setBorder(new TitledBorder("系统路径"));//title - 边框应显示的标题
sysPathPanel.setLayout(new GridLayout(0,1));
sysSetPanel.add(sysPathPanel);
sysPathPanel.add(new JLabel("程序升级路径"));
updatePathTField = new JTextField(preferences.get("updatePath", "请输入路径"));
sysPathPanel.add(updatePathTField);
sysPathPanel.add(new JLabel("系统公告路径:"));
placardPathTField = new JTextField(preferences.get("placardPath","请输入路径"));
sysPathPanel.add(placardPathTField);
sysPathPanel.add(new JLabel("公共程序路径:"));
pubPathTField = new JTextField(preferences.get("pubPath", "请输入路径"));
sysPathPanel.add(pubPathTField);
final JButton pathOKButton = new JButton("确定");
pathOKButton.setActionCommand("sysOK");
pathOKButton.addActionListener(new SysSetPanelOKListener());
sysSetPanel.add(pathOKButton);
final JPanel loginPanel = new JPanel();
loginPanel.setMaximumSize(new Dimension(600, 90));
loginPanel.setBorder(new TitledBorder("登录升级服务器"));
final GridLayout gridLayout_1 = new GridLayout(0, 1);
gridLayout_1.setVgap(5);
loginPanel.setLayout(gridLayout_1);
sysSetPanel.add(loginPanel);
final JPanel panel_7 = new JPanel();
panel_7.setLayout(new BoxLayout(panel_7, BoxLayout.X_AXIS));
loginPanel.add(panel_7);
panel_7.add(new JLabel("用户名:"));
userNameTField = new JTextField(preferences.get("username", "请输入用户名"));
panel_7.add(userNameTField);
final JPanel panel_8 = new JPanel();
panel_8.setLayout(new BoxLayout(panel_8, BoxLayout.X_AXIS));
loginPanel.add(panel_8);
panel_8.add(new JLabel("密 码:"));
passwordTField = new JPasswordField("*****");
panel_8.add(passwordTField);
final JButton loginOKButton = new JButton("确定");
sysSetPanel.add(loginOKButton);
loginOKButton.setActionCommand("loginOK");
loginOKButton.addActionListener(new SysSetPanelOKListener());
final JPanel ipPanel = new JPanel();
final GridLayout gridLayout_2 = new GridLayout(0, 1);
gridLayout_2.setVgap(5);
ipPanel.setLayout(gridLayout_2);
ipPanel.setMaximumSize(new Dimension(600, 90));
ipPanel.setBorder(new TitledBorder("IP搜索范围"));
sysSetPanel.add(ipPanel);
final JPanel panel_5 = new JPanel();
panel_5.setLayout(new BoxLayout(panel_5, BoxLayout.X_AXIS));
ipPanel.add(panel_5);
panel_5.add(new JLabel("起始IP:"));
ipStartTField = new JTextField(preferences.get("ipStart", "192.168.0.1"));
panel_5.add(ipStartTField);
final JPanel panel_6 = new JPanel();
panel_6.setLayout(new BoxLayout(panel_6, BoxLayout.X_AXIS));
ipPanel.add(panel_6);
panel_6.add(new JLabel("终止IP:"));
ipEndTField = new JTextField(preferences.get("ipEnd", "192.168.1.255"));
panel_6.add(ipEndTField);
final JButton ipOKButton = new JButton("确定");
ipOKButton.setActionCommand("ipOK");
ipOKButton.addActionListener(new SysSetPanelOKListener());
sysSetPanel.add(ipOKButton);
return scrollPane;
}
//----------------------------------------------------------------------------------
private JScrollPane createUserList(){// 用户列表面板
JScrollPane scrollPane = new JScrollPane();
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
addUserPopup(chatTree,getPopupMenu());// 为用户添加弹出菜单
scrollPane.setViewportView(chatTree);
scrollPane.setBorder(new EmptyBorder(0,0,0,0));
chatTree.addMouseListener(new ChatTreeMouseListener());
return scrollPane;
}
//----------------------------------------------------------------------------------
private JScrollPane createSysToolPanel() {// 系统工具面板
JPanel sysToolPanel = new JPanel(); // 系统工具面板
sysToolPanel.setLayout(new BorderLayout());
JScrollPane sysToolScrollPanel = new JScrollPane();
sysToolScrollPanel
.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
sysToolScrollPanel.setBorder(new EmptyBorder(0, 0, 0, 0));
sysToolScrollPanel.setViewportView(sysToolPanel);
sysToolPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
JPanel interfacePanel = new JPanel();
sysToolPanel.add(interfacePanel, BorderLayout.NORTH);
interfacePanel.setLayout(new BorderLayout());
interfacePanel.setBorder(new TitledBorder("界面选择-再次启动生效"));
faceList = new JList(new String[]{"当前系统", "java默认"});
interfacePanel.add(faceList);
faceList.setBorder(new BevelBorder(BevelBorder.LOWERED));
final JPanel interfaceSubPanel = new JPanel();
interfaceSubPanel.setLayout(new FlowLayout());
interfacePanel.add(interfaceSubPanel, BorderLayout.SOUTH);
selectInterfaceOKButton = new JButton("确定");
selectInterfaceOKButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
preferences.put("lookAndFeel", faceList.getSelectedValue().toString());
JOptionPane.showMessageDialog(EQ.this, "重新运行本软件后生效");
}
});
interfaceSubPanel.add(selectInterfaceOKButton);
JPanel searchUserPanel = new JPanel(); // 用户搜索面板
sysToolPanel.add(searchUserPanel);
searchUserPanel.setLayout(new BorderLayout());
final JPanel searchControlPanel = new JPanel();
searchControlPanel.setLayout(new GridLayout(0, 1));
searchUserPanel.add(searchControlPanel, BorderLayout.SOUTH);
final JList searchUserList = new JList(new String[]{"检测用户列表"});// 新添加用户列表
final JScrollPane scrollPane_2 = new JScrollPane(searchUserList);
scrollPane_2.setDoubleBuffered(true);
searchUserPanel.add(scrollPane_2);
searchUserList.setBorder(new BevelBorder(BevelBorder.LOWERED));
searchUserButton = new JToggleButton();
searchUserButton.setText("搜索新用户");
searchUserButton.addActionListener(new SearchUserActionListener(searchUserList));
searchControlPanel.add(progressBar);
searchControlPanel.add(searchUserButton);
searchUserPanel.setBorder(new TitledBorder("搜索用户"));
final JPanel sysUpdatePanel = new JPanel();
sysUpdatePanel.setOpaque(false);
sysUpdatePanel.setLayout(new GridBagLayout());
sysUpdatePanel.setBorder(new TitledBorder("系统操作"));
sysToolPanel.add(sysUpdatePanel, BorderLayout.SOUTH);
final JButton sysUpdateButton = new JButton("系统更新");
final GridBagConstraints gridBagConstraints_1 = new GridBagConstraints();
gridBagConstraints_1.gridx = 0;
gridBagConstraints_1.gridy = 0;
sysUpdatePanel.add(sysUpdateButton, gridBagConstraints_1);
sysUpdateButton.addActionListener(new SysUpdateListener());// 添加系统更新事件
final JLabel updateLabel = new JLabel("最近更新:");
final GridBagConstraints updateLabelLayout = new GridBagConstraints();
updateLabelLayout.gridy = 1;
updateLabelLayout.gridx = 0;
sysUpdatePanel.add(updateLabel, updateLabelLayout);
final JLabel updateDateLabel = new JLabel();// 程序更新日期标签
Date date = new Date(localFile.lastModified());
String dateStr = String.format("%tF %<tr", date);
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><center><font color=red><b>无法登录</b><br>未设置升级路径</font></center></html>";
updateInfo.setText(info);
continue;
}
netFile = new File(netFilePath);
if(netFile.exists()){
Date netDate = new Date(netFile.lastModified());
if(!localFile.exists()){
info = "<html><font color=blue>本地程序位置出错!</font></html>";
}else{
Date localDate = new Date(localFile.lastModified());
if(netDate.after(localDate)){
info = "<html><font color=blue>网络上有最新程序!</font></html>";
pushMessage(info);
}else{
info = "<html><font color=green>现在是最新程序!</font></html>";
}
}
}else{
info = "<html><center><font color=red><b>无法访问</b><br>升级路径</font></center></html>";
}
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(passwordTField.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,dp,chatTree);
}
}
}
}).start();
}
//----------------------------------------------------------------------------------
private void addUserPopup(Component component, final JPopupMenu popup){// 添加用户弹出菜单
component.addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent e){
if(e.isPopupTrigger()){
showMenu(e);
}
}
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger())
showMenu(e);
}
private void showMenu(MouseEvent e){
if(chatTree.getSelectionPaths() == null){
popupMenu.getComponent(0).setEnabled(false);
popupMenu.getComponent(2).setEnabled(false);
popupMenu.getComponent(3).setEnabled(false);
popupMenu.getComponent(4).setEnabled(false);
popupMenu.getComponent(5).setEnabled(false);
}else{
if(chatTree.getSelectionPaths().length < 2){
popupMenu.getComponent(3).setEnabled(false);
}else {
popupMenu.getComponent(3).setEnabled(true);
}
popupMenu.getComponent(0).setEnabled(true);
popupMenu.getComponent(2).setEnabled(true);
popupMenu.getComponent(4).setEnabled(true);
popupMenu.getComponent(5).setEnabled(true);
}
popup.show(e.getComponent(), e.getX(), e.getY());
}
});
}
//----------------------------------------------------------------------------------
private void saveLocation(){// 保存主窗体位置的方法
location = getBounds();
dao.updateLocation(location);
}
//----------------------------------------------------------------------------------
protected JPopupMenu getPopupMenu(){// 创建用户弹出菜单
if (popupMenu == null) {
popupMenu = new JPopupMenu();
popupMenu.setOpaque(false);
}
final JMenuItem rename = new JMenuItem();
popupMenu.add(rename);
rename.addActionListener(new RenameActionListener());
rename.setText("更名");
final JMenuItem addUser = new JMenuItem();
addUser.addActionListener(new AddUserActionListener());
popupMenu.add(addUser);
addUser.setText("添加用户");
final JMenuItem delUser = new JMenuItem();
delUser.addActionListener(new delUserActionListener());
popupMenu.add(delUser);
delUser.setText("删除用户");
final JMenuItem messagerGroupSend = new JMenuItem();
messagerGroupSend
.addActionListener(new messagerGroupSendActionListener());
messagerGroupSend.setText("信使群发");
popupMenu.add(messagerGroupSend);
final JMenuItem accessComputerFolder = new JMenuItem("访问主机资源");
accessComputerFolder.setActionCommand("computer");
popupMenu.add(accessComputerFolder);
accessComputerFolder
.addActionListener(new accessFolderActionListener());
final JMenuItem accessPublicFolder = new JMenuItem();
popupMenu.add(accessPublicFolder);
accessPublicFolder.setOpaque(false);
accessPublicFolder.setText("访问公共程序");
accessPublicFolder.setActionCommand("public");
accessPublicFolder.addActionListener(new accessFolderActionListener());
return popupMenu;
}
//----------------------------------------------------------------------------------
private void updateProject(){// 程序更新方法
netFilePath = preferences.get("updatePath", "EQ.jar");
if(netFilePath.equals("EQ.jar")){
pushMessage("未设置升级路径");
return;
}
netFile = new File(netFilePath);
localFile = new File(user_dir + File.separator + "EQ.jar");
if (localFile != null && netFile != null && netFile.exists()
&& localFile.exists()) {
Date netDate = new Date(netFile.lastModified());
Date localDate = new Date(localFile.lastModified());
if (netDate.after(localDate)) {
new Thread(new Runnable() {
public void run() {
try {
Dialog frameUpdate = new UpdateFrame();
frameUpdate.setVisible(true);
Thread.sleep(2000);
FileInputStream fis = new FileInputStream(netFile);
FileOutputStream fout = new FileOutputStream(
localFile);
int len = fis.available();
if (len > 0) {
byte[] data = new byte[len];
if (fis.read(data) > 0) {
fout.write(data);
}
}
fis.close();
fout.close();
frameUpdate.setVisible(false);
frameUpdate = null;
showMessageDialog("更新完毕,请重新启动程序。");
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
} else {
showMessageDialog("已经是最新的程序了。");
}
}
}
//----------------------------------------------------------------------------------
private void checkPlacard() { // 检测公告信息方法
String placardDir = preferences.get("placardPath", null);
if (placardDir == null) {
pushMessage("未设置公告路径");
return;
}
File placard = new File(placardDir);
try {
if (placard.exists() && placard.isFile()) {
StringBuilder placardStr = new StringBuilder();
Scanner sc = new Scanner(new FileInputStream(placard));
while (sc.hasNextLine()) {
placardStr.append(sc.nextLine());
}
pushMessage(placardStr.toString());
}
} catch (FileNotFoundException e) {
pushMessage("公告路径错误,或公告文件不存在");
}
}
//----------------------------------------------------------------------------------
public void setStatic(String str){// 设置状态栏信息
if(stateLabel != null){
stateLabel.setText(str);
}
}
public void pushMessage(String info){// 堆压信息
if(!messageStack.contains(info)){
messageStack.push(info);
}
}
private void showMessageDialog(String message){
JOptionPane.showMessageDialog(this, message);
}
//----------------------------------------------------------------------------------
private String showInputDialog(String str){// 显示输入对话框
String newName = JOptionPane.showInputDialog(this,
"<html>输入<font color=red>" + str + "</font>的新名字</html>");
return newName;
}
private class accessFolderActionListener implements ActionListener {// 访问资源
public void actionPerformed(final ActionEvent e) {
TreePath path = chatTree.getSelectionPath();
if (path == null)
return;
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path
.getLastPathComponent();
User user = (User) node.getUserObject();
String ip = "\\\\"+user.getIp();
String command = e.getActionCommand();
if (command.equals("computer")) {
Resource.startFolder(ip);
}
if (command.equals("public")) {
String serverPaeh = preferences.get("pubPath", null);
if (serverPaeh == null) {
pushMessage("未设置公共程序路径");
return;
}
Resource.startFolder(serverPaeh);
}
}
}
private class RenameActionListener implements ActionListener {// 更名
public void actionPerformed(final ActionEvent e) {
TreePath path = chatTree.getSelectionPath();
if (path == null)
return;
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path
.getLastPathComponent();
User user = (User) node.getUserObject();
String newName = showInputDialog(user.getName());
if (newName != null && !newName.isEmpty()) {
user.setName(newName);
dao.updateUser(user);
DefaultTreeModel model = (DefaultTreeModel) chatTree.getModel();
model.reload();
chatTree.setSelectionPath(path);
initUserInfoButton();
}
}
}
private class FrameWindowListener extends WindowAdapter {
public void windowClosing(final WindowEvent e) {// 系统关闭事件
setVisible(false);
}
}
private class AddUserActionListener implements ActionListener {
public void actionPerformed(final ActionEvent e) {// 添加用户
String ip = JOptionPane.showInputDialog(EQ.this, "输入新用户IP地址");
if (ip != null)
chatTree.addUser(ip, "add");
}
}
private class delUserActionListener implements ActionListener {
public void actionPerformed(final ActionEvent e) {// 删除用户
chatTree.delUser();
}
}
private class messagerGroupSendActionListener implements ActionListener {// 信使群发
public void actionPerformed(final ActionEvent e) {
String message = JOptionPane.showInputDialog(EQ.this, "请输入群发信息",
"信使群发", JOptionPane.INFORMATION_MESSAGE);
if (message != null && !message.equals("")) {
TreePath[] selectionPaths = chatTree.getSelectionPaths();
Resource.sendGroupMessenger(selectionPaths, message);
} else if (message != null && message.isEmpty()) {
JOptionPane.showMessageDialog(EQ.this, "不能发送空信息!");
}
}
}
private void SystemTrayInitial() { // 系统栏初始化
if (!SystemTray.isSupported()) // 判断当前系统是否支持系统栏
return;
try {
String title = "TT";
String company = "成都市同道科技有限公司";
SystemTray sysTray = SystemTray.getSystemTray();
Image image = Toolkit.getDefaultToolkit().getImage(
EQ.class.getResource("/icons/sysTray.png"));// 系统栏图标
trayicon = new TrayIcon(image, title + "\n" + company, createMenu());
trayicon.setImageAutoSize(true);
trayicon.addActionListener(new SysTrayActionListener());
sysTray.add(trayicon);
trayicon.displayMessage(title, company, MessageType.INFO);
} catch (Exception e) {
e.printStackTrace();
}
}
private PopupMenu createMenu() { // 创建系统栏菜单的方法
PopupMenu menu = new PopupMenu();
MenuItem exitItem = new MenuItem("退出");
exitItem.addActionListener(new ActionListener() { // 系统栏退出事件
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
MenuItem openItem = new MenuItem("打开");
openItem.addActionListener(new ActionListener() {// 系统栏打开菜单项事件
public void actionPerformed(ActionEvent e) {
if (!isVisible()) {
setVisible(true);
toFront();
} else
toFront();
}
});
// 系统栏的访问服务器菜单项事件
MenuItem publicItem = new MenuItem("访问服务器");
publicItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String serverPaeh = preferences.get("pubPath", null);
if (serverPaeh == null) {
pushMessage("未设置公共程序路径");
return;
}
Resource.startFolder(serverPaeh);
}
});
menu.add(publicItem);
menu.add(openItem);
menu.addSeparator();
menu.add(exitItem);
return menu;
}
class SysTrayActionListener implements ActionListener {// 系统栏双击事件
public void actionPerformed(ActionEvent e) {
setVisible(true);
toFront();
}
}
}
相关推荐
Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。
城市旅游产业的日新月异影响着村镇旅游产业的发展变化。网络、电子科技的迅猛前进同样牵动着旅游产业的快速成长。随着人们消费理念的不断发展变化,越来越多的人开始注意精神文明的追求,而不仅仅只是在意物质消费的提高。塞北村镇旅游网站的设计就是帮助村镇发展旅游产业,达到宣传效果,带动一方经济发展。而在线消费与查询正在以高效,方便,时尚等的特点成为广大互联网用户的首选。塞北村镇旅游网站设计与开发以方便、快捷、费用低的优点正慢慢地进入人们的生活。人们从传统的旅游方式转变为在线预览,减轻了劳动者的工作量。使得旅游从业人员有更多时间来获取、了解、掌握信息。 塞北村镇旅游网站根据当地旅游风景和特色的实际情况,设计出一套适合当地旅游信息网站,通过网络,实现该网站的推广从而达到宣传的效果。 本系统在设计方面采用JSP和Java语言以及html脚本语言,同时采用B/S模式,进行各个界面和每个功能的设计与实现,后台管理与设计选用了SQL Server 2005数据库,前台设计与后台管理相结合,共同完成各功能模块的功能。
JSP考试系统_jspks.rar是一个为计算机专业学生和教师设计的JSP源码资料包,它提供了一个全面的、易于使用的在线考试平台。这个系统是基于Java Server Pages (JSP)技术构建的,这是一种用于创建动态网页的服务器端技术。通过这个系统,用户可以创建、管理和参加在线考试。这个系统的主要功能包括:用户注册和登录,试题管理(包括添加、修改和删除试题),试卷管理(包括创建、编辑和删除试卷),考试管理(包括开始、暂停和结束考试),成绩管理(包括查看和统计成绩)等。此外,系统还提供了丰富的试题类型,如选择题、填空题、判断题和简答题等,以满足不同的考试需求。JSP考试系统的界面设计简洁明了,操作方便,无论是教师还是学生都可以轻松上手。对于教师来说,他们可以通过这个系统轻松地管理试题和试卷,节省了大量的时间和精力。对于学生来说,他们可以随时随地参加在线考试,方便快捷。总的来说,JSP考试系统_jspks.rar是一个非常实用的JSP源码资料包,它不仅可以帮助学生更好地学习和掌握JSP技术,也可以帮助教师更有效地管理在线考试。无论是对于学生还是教师,这个系统都是一个不可或缺的工具。重
Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。
词向量
Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。
基于matlab开发的光谱数据预处理程序,包括MSC,SNV,归一化,中心化,导数等等.rar
优秀源码设计,详情请查看资源源码内容
基于matlab开发的TD-LTE随机接入过程前导序列检测算法Matlab信道仿真.rar
词向量 词向量(Word Vectors)是一种用来表示词语语义和语法信息的数学模型。它将词语转换为固定长度的实数向量,使得词向量之间的距离(通常使用余弦相似度)可以反映出词语之间的语义关系。词向量在自然语言处理和机器学习领域有广泛的应用,例如文本分类、情感分析、句子相似度计算等。 词向量的发展经历了从传统的one-hot表示到分布式表示的转变。传统的one-hot表示将每个词语表示为一个高维稀疏的向量,向量中只有一个元素为1,其余元素都为0,表示词语在词汇表中的位置。然而,这种表示方式无法准确捕捉词语之间的语义关系。 为了解决这个问题,分布式表示方法被提出。分布式表示将每个词语表示为一个低维稠密的实数向量,其中每个元素都包含了词语的语义和语法信息。这种表示方式的关键思想是,具有相似语义和上下文的词语在向量空间中更加接近。 现在广泛应用的词向量模型有许多种,其中最著名的是Word2Vec模型和GloVe模型。Word2Vec是一种基于神经网络的模型,它通过一种称为连续词袋(CBOW)和另一种称为跳字(Skip-gram)的训练方法来学习词向量。GloVe模型是一种基于全局词频的词
Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。
超市会员积分管理系统主要用于实现了企业管理数据统计等。本系统结构如下: (1)网络会员管理中心界面: 会员修改密码信息模块:实现会员密码功能; 会员登陆模块:实现会员登陆功能; 会员注册模块:实现会员注册功能; 留言板模块:实现留言板留言功能 (2)后台管理界面: 系统用户管理模块:实现管理员的增加、查看功能; 会员信息管理模块:实现会员信息的增加、修改、查看功能; 注册用户管理模块:实现注册用户的增加、修改、查看功能; 会员卡管理模块:实现会员卡信息的增加、查看功能; 商品销售管理模块:实现商品信息的增加、查看功能; 会员积分管理模块:实现合作公司信息的增加、查看功能; 信息统计模块:实现数据统计报表功能; 留言板模块:实现留言板信息的增加、修改、查看功能;
信息办公XML考试系统_xmlks.rar是一款专为计算机专业设计的JSP源码资料包。这个资料包包含了丰富的功能和特性,旨在为教育机构、培训中心和企业提供一个完整的在线考试解决方案。通过使用这个资料包,用户可以轻松地创建和管理自己的在线考试平台,实现对学员的考试、评分和成绩管理。首先,这个资料包采用了流行的JSP技术,结合了XML数据存储和处理,使得系统具有很高的可扩展性和灵活性。用户可以方便地根据自己的需求定制和修改系统的功能和界面。同时,系统还支持多种题型,如选择题、填空题、判断题等,满足不同类型考试的需求。其次,信息办公XML考试系统_xmlks.rar具有良好的用户体验和易用性。系统的界面设计简洁明了,操作流程清晰易懂,使得考生可以快速上手并完成考试。同时,系统还提供了丰富的帮助文档和教程,方便用户在使用过程中随时查阅和学习。此外,这个资料包还具有强大的后台管理功能。管理员可以轻松地添加、删除和修改试题,设置考试参数,查看考生的成绩和答题情况。同时,系统还支持多种权限管理,确保数据的安全性和保密性。总之,信息办公XML考试系统_xmlks.rar是一款功能强大、易用性高、可扩展
该资源包“130222.rar”是一个针对计算机专业学生或开发者设计的基于Java服务器页面(JSP)、Servlet以及MySQL数据库的博客系统网站的源码资料。这个压缩文件包含了构建一个功能齐全的动态网站所需的全部源代码和相关文档,它允许用户通过互联网发布文章、分享观点,并与他人进行互动。在内容上,它可能包含了多个JSP页面文件,用于展示博客首页、文章列表、文章内容页、写文章的表单等界面;包含了Servlet类文件,用于处理用户的请求、与数据库交互以及业务逻辑的处理;还可能包含配置文件如web.xml,用于配置Servlet映射等。至于数据库部分,则包括了MySQL的数据库文件,其中存储了博客系统的数据结构、初始数据以及存储过程等。此资料包是一套学习和实践Web开发的好材料,尤其适合那些想要深入学习JSP、Servlet和数据库交互技术的学习者。通过分析和运行这些源码,学习者可以了解Web应用的开发流程,掌握如何在Java Web环境中使用MVC设计模式,以及如何实现用户身份验证、会话管理、数据持久化等关键功能。由于是基于JSP的传统Web开发技术,虽然现代Web开发领域已逐渐向全
可视化图库Pandas_Alive实现动态图表绘制,使用时减少数据会使生成GIF的时间变短。通过对CSV文件分析,实现动态条形图、动态曲线图、气泡图、饼状图、地理空间图等多个动态图表的可视化分析。
基于SSM的“停车场管理系统”的设计与实现基于SSM的“停车场管理系统”的设计与实现基于SSM的“停车场管理系统”的设计与实现基于SSM的“停车场管理系统”的设计与实现基于SSM的“停车场管理系统”的设计与实现基于SSM的“停车场管理系统”的设计与实现基于SSM的“停车场管理系统”的设计与实现基于SSM的“停车场管理系统”的设计与实现基于SSM的“停车场管理系统”的设计与实现
Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。
基于matlab实现此压缩包包含语音信号处理中的语音变声代码加音频.rar
Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。
学生成绩管理系统c