📄 maingui.java
字号:
selectAllUserInfo.setEnabled(true);
menuItem.setEnabled(true);
}
menuItem_9.setText("退出");
popupMenu_1.add(menuItem_9);
new Time().start();
}
public void showGUI()
{
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(700,200,247, 450);
frame.setVisible(true);
}
class Time extends Thread
{
SimpleDateFormat sim=new SimpleDateFormat("hh:mm:ss");
public void run()
{
while(true)
{
String str=sim.format(new Date(System.currentTimeMillis()));
time.setText("当前时间:"+str);
try {
sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Tree extends Thread
{
Vector comm;
Vector user;
String commend;
public void run()
{
while(true)
{
try {
comm=(Vector)ToServerProcess.getMessage();
commend=(String)comm.get(0);
} catch (IOException e) {
// TODO Auto-generated catch block
JOptionPane.showMessageDialog(frame,"与服务器断开连接,请重新登录!","警告",JOptionPane.WARNING_MESSAGE,null);
frame.dispose();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
break;
}
if(commend.trim().equals("online"))//有人上线。。更新树
{
user=(Vector)comm.get(1);
for(int i=0;i<MainGUI.top.getChildCount();i++){
DefaultMutableTreeNode removenode = (DefaultMutableTreeNode)MainGUI.top.getChildAt(i);
if(removenode.getUserObject().toString().equals((String)user.get(3)))
{
//
ImageIcon image1=new ImageIcon(System.getProperty("user.dir")+(String)user.get(9));
Image image= image1.getImage();
Image smallImage=image.getScaledInstance(20,20, Image.SCALE_SMOOTH);
ImageIcon smallIcon1=new ImageIcon(smallImage);
removenode.add(new DefaultMutableTreeNode(new IconData(smallIcon1,(String)user.get(1))));
}
}
list.add(user);
MainGUI.m_model.reload();//更新树模型
new CautionGUI((String)user.get(9),(String)user.get(3),(String)user.get(1),true,2000);
}else if(commend.trim().equals("exit"))//下线更新树
{
user=(Vector)comm.get(1);
for(int i=0;i<MainGUI.top.getChildCount();i++){
DefaultMutableTreeNode removenode = (DefaultMutableTreeNode)MainGUI.top.getChildAt(i);
if(removenode.getUserObject().toString().equals((String)user.get(3)))
{
for(int j=0;j<removenode.getChildCount();j++)
{
DefaultMutableTreeNode remove = (DefaultMutableTreeNode)removenode.getChildAt(j);
if(remove.getUserObject().toString().equals((String)user.get(1)))
{
removenode.remove(j);
}
}
}
}
for(int i=0;i<list.size();i++)//删除在在线用户数组信息里的记录
{
Vector v=(Vector) list.get(i);
if(v.get(0).equals(user.get(0)))
{
list.remove(i);
}
}
MainGUI.m_model.reload();//更新树模型
new CautionGUI((String)user.get(9),(String)user.get(3),(String)user.get(1),false,2000);
}else if(commend.trim().equals("系统信息"))
{
JOptionPane.showMessageDialog(frame,(String)comm.get(1),"服务器消息",JOptionPane.WARNING_MESSAGE,null);
}else if(commend.trim().equals("群聊"))
{
int i=qun.size();
if(i==0)
{
int j=JOptionPane.showConfirmDialog(frame,"有公司之间的聊天信息,打开查看?","提示",JOptionPane.YES_OPTION,JOptionPane.INFORMATION_MESSAGE,null);
if(j==0)
{
BandChatGUI band1=new BandChatGUI(name,dept);
band1.showGUI();
band1.receive.append((String)comm.get(1));
FileStream.writeFile(sim.format(new Date(System.currentTimeMillis())),(String)comm.get(1));
band1.receive.setCaretPosition(BandChatGUI.receive.getText().length());
qun.put("1",band1);
}
}else
{
BandChatGUI band=(BandChatGUI) qun.get("1");
band.receive.append((String)comm.get(1));
FileStream.writeFile(sim.format(new Date(System.currentTimeMillis())),(String)comm.get(1));
band.receive.setCaretPosition(BandChatGUI.receive.getText().length());
}
}else if(commend.trim().equals("所有用户信息"))
{
Vector info=(Vector)comm.get(1);
new ShowAllUserInfoGUI(info).showGUI();
}else if(commend.trim().equals("公司公告"))
{
Vector g=(Vector)comm.get(1);
String de=(String)comm.get(2);
new ShowAdvertiseInfo(g,de,dept,quanxian).showGUI();
}else if(commend.trim().equals("部门公告"))
{
String name=(String)comm.get(1);
ShowAdvertiseInfo.deptTextArea.setText(name.trim());
}else if(commend.trim().equals("修改部门公告"))
{
String boo=(String)comm.get(1);
if(boo.trim().equals("yes"))
{
JOptionPane.showMessageDialog(null,"部门公告修改成功!","提示",JOptionPane.INFORMATION_MESSAGE,null);
}else
JOptionPane.showMessageDialog(null,"部门公告修改失败!","提示",JOptionPane.INFORMATION_MESSAGE,null);
}else if(commend.trim().equals("部门名称"))
{
Vector g=(Vector)comm.get(1);
new ShowDeptInfoGUI(g).showGUI();
}else if(commend.trim().equals("部门信息"))
{
Vector info=(Vector)comm.get(1);
ShowDeptInfoGUI.textField.setText((String) info.get(0));
ShowDeptInfoGUI.deptName.setText((String) info.get(1));
ShowDeptInfoGUI.deptMastr.setText((String) info.get(2));
ShowDeptInfoGUI.deptadress.setText((String) info.get(3));
ShowDeptInfoGUI.deptTel.setText((String) info.get(4));
ShowDeptInfoGUI.textArea.setText((String) info.get(5));
}else if(commend.trim().equals("修改部门信息"))
{
String boo=(String)comm.get(1);
if(boo.trim().equals("yes"))
{
JOptionPane.showMessageDialog(null,"部门信息修改成功!","提示",JOptionPane.INFORMATION_MESSAGE,null);
}else
JOptionPane.showMessageDialog(null,"部门信息修改失败!","提示",JOptionPane.INFORMATION_MESSAGE,null);
}else if(commend.trim().equals("修改自身密码"))
{
String boo=(String)comm.get(1);
if(boo.trim().equals("yes"))
{
JOptionPane.showMessageDialog(null,"修改自身密码成功!","提示",JOptionPane.INFORMATION_MESSAGE,null);
}else
JOptionPane.showMessageDialog(null,"修改自身密码失败!","提示",JOptionPane.INFORMATION_MESSAGE,null);
}
else if(commend.trim().equals("检测ID"))
{
String boo=(String)comm.get(1);
if(boo.trim().equals("yes"))
{
JOptionPane.showMessageDialog(null,"此ID可以使用!","提示",JOptionPane.INFORMATION_MESSAGE,null);
InsertInfoGUI.idField.setEditable(false);
}else
{
JOptionPane.showMessageDialog(null,"此ID已经存在!","提示",JOptionPane.INFORMATION_MESSAGE,null);
InsertInfoGUI.idField.setEditable(true);
}
}
else if(commend.trim().equals("插入员工"))
{
String boo=(String)comm.get(1);
if(boo.trim().equals("yes"))
{
JOptionPane.showMessageDialog(null,"插入成功!","提示",JOptionPane.INFORMATION_MESSAGE,null);
}else
{
JOptionPane.showMessageDialog(null,"插入失败!","提示",JOptionPane.INFORMATION_MESSAGE,null);
}
}
else if(commend.trim().equals("添加用户"))
{
Vector boo=(Vector)comm.get(1);
new InsertInfoGUI(boo).showGUI();
}
else if(commend.trim().equals("用户信息"))
{
String[] str=(String[])comm.get(1);
if(str[0].equals("F"))
{
JOptionPane.showMessageDialog(null,"没有此用户!","提示",JOptionPane.INFORMATION_MESSAGE,null);
return;
}
DeleteUserInfo.delete.setEnabled(true);
DeleteUserInfo.nameTextField.setText(str[1]);
DeleteUserInfo.textField_2.setText(str[3]);
DeleteUserInfo.depttextField.setText(str[4]);
DeleteUserInfo.textArea.setText(str[12]);
DeleteUserInfo.button.setIcon(SwingResourceManager.getIcon(MainGUI.class, str[11]));
DeleteUserInfo.textField.setEditable(false);
}
else if(commend.trim().equals("删除用户"))
{
String boo=(String)comm.get(1);
if(boo.trim().equals("yes"))
{
JOptionPane.showMessageDialog(null,"删除用户成功!","提示",JOptionPane.INFORMATION_MESSAGE,null);
DeleteUserInfo.delete.setEnabled(false);
DeleteUserInfo.nameTextField.setText("");
DeleteUserInfo.textField_2.setText("");
DeleteUserInfo.depttextField.setText("");
DeleteUserInfo.textArea.setText("");
DeleteUserInfo.textField.setText("");
DeleteUserInfo.button.setIcon(SwingResourceManager.getIcon(MainGUI.class, ""));
DeleteUserInfo.textField.setEditable(true);
}else
{
JOptionPane.showMessageDialog(null,"删除用户失败!","提示",JOptionPane.INFORMATION_MESSAGE,null);
}
}
else if(commend.trim().equals("查看用户信息"))
{
String[] str=(String[])comm.get(1);
if(str[0].equals("F"))
{
JOptionPane.showMessageDialog(null,"没有此用户信息!","提示",JOptionPane.INFORMATION_MESSAGE,null);
}
new ShowUserInfoGUI(str).showGUI();
}else if(commend.trim().equals("私聊"))
{
String id1=(String)comm.get(1);//自己的ID
String dept1=(String)comm.get(2);//对方的部门名字
String name1=(String)comm.get(3);//对方的名字
String pic1=(String)comm.get(4);//对方的头像
String id2=(String)comm.get(5);//对方的ID
String str=(String)comm.get(6);//聊天内容
SingleChatGUI single=(SingleChatGUI)MainGUI.siliao.get(id2.trim());
if(single==null)
{
int i=JOptionPane.showConfirmDialog(frame,dept1+"的"+name1+"向你发送信息,打开查看。","提示",JOptionPane.YES_OPTION,JOptionPane.INFORMATION_MESSAGE,null);
if(i==0)
{
// //(对方头像,对方部门名字,对方名字,对方ID,自己的名字,自己部门名字,自己的头像,自己ID)
SingleChatGUI sin=new SingleChatGUI(pic1,dept1,name1,id2,name,dept,pic,id,false);
sin.showGUI();
single.receiveField.append(str);
siliao.put(id2,sin);
}
}else
{
single.receiveField.append(str);
single.receiveField.setCaretPosition(single.receiveField.getText().length());
}
}else if(commend.trim().equals("密码用户"))
{
String[] str=(String[])comm.get(1);
if(str[0].equals("F"))
JOptionPane.showMessageDialog(null,"没有此用户!","提示",JOptionPane.INFORMATION_MESSAGE,null);
else
{
UpdatePwd.nametextField.setText(str[1]);
UpdatePwd.textField.setEditable(false);
UpdatePwd.commit.setEnabled(true);
}
}else if(commend.trim().equals("修改用户密码"))
{
String boo=(String)comm.get(1);
if(boo.trim().equals("yes"))
{
JOptionPane.showMessageDialog(null,"密码修改成功!","提示",JOptionPane.INFORMATION_MESSAGE,null);
}else
{
JOptionPane.showMessageDialog(null,"密码修改失败!","提示",JOptionPane.INFORMATION_MESSAGE,null);
}
}else if(commend.trim().equals("更新个人信息")){
String s = (String)comm.get(1);
if(s.trim().equals("yes"))
JOptionPane.showMessageDialog(null,"修改成功!","提示",JOptionPane.INFORMATION_MESSAGE,null);
else
JOptionPane.showMessageDialog(null,"修改失败!","提示",JOptionPane.INFORMATION_MESSAGE,null);
}else if(commend.trim().equals("查找用户信息")){
String[] str=(String[])comm.get(1);
if(str[0].trim().equals("F"))
JOptionPane.showMessageDialog(null,"未找到此ID!","提示",JOptionPane.INFORMATION_MESSAGE,null);
else{
UpdateUserInfo.nametextField.setText(str[1].trim());
if(str[5].trim().equals("男"))
UpdateUserInfo.men.setSelected(true);
else
UpdateUserInfo.women.setSelected(true);
UpdateUserInfo.postiontextField.setText(str[3].trim());
UpdateUserInfo.teltextField.setText(str[8].trim());
UpdateUserInfo.emailField.setText(str[9].trim());
UpdateUserInfo.yearField.setText(str[7].substring(0,10).trim());
UpdateUserInfo.textArea.setText(str[12].trim());
UpdateUserInfo.head.setIcon(SwingResourceManager.getIcon(MainGUI.class,str[11]));
int con=UpdateUserInfo.comboBox.getItemCount();
for(int i=0;i<con;i++){
String str1=(String)UpdateUserInfo.comboBox.getItemAt(i);
if(str[4].trim().equals(str1.trim())){
UpdateUserInfo.comboBox.setSelectedIndex(i);
}
}
}
}else if(commend.trim().equals("修改用户信息")){
String str=(String)comm.get(1);
if(str.trim().equals("yes"))
JOptionPane.showMessageDialog(null,"修改成功!","提示",JOptionPane.INFORMATION_MESSAGE,null);
else
JOptionPane.showMessageDialog(null,"修改失败!","提示",JOptionPane.INFORMATION_MESSAGE,null);
}else if(commend.trim().equals("个人用户信息"))
{
String[] str=(String[])comm.get(1);
new UpdateSelfUser(str).showGUI();
}
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
//new MainGUI().showGUI();
}
private static void addPopup(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) {
popup.show(e.getComponent(), e.getX(), e.getY());
}
});
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -