Java课程设计——人事管理系统
Posted 王醒燕
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java课程设计——人事管理系统相关的知识,希望对你有一定的参考价值。
主界面代码:
1 package PersonSystem; 2 3 import java.awt.*; 4 import java.awt.event.*; 5 import javax.swing.*; 6 import javax.swing.event.*; 7 import javax.swing.tree.*; 8 import java.net.*; 9 /** 10 * 11 * 人事管理系统主界面 12 * 13 */ 14 public class HrMain extends JFrame implements ActionListener,TreeSelectionListener 15 { 16 Dimension faceSize = new Dimension(650,450); 17 Image icon; 18 //建立JTree菜单 19 JTree tree; 20 DefaultMutableTreeNode root;//人事管理系统 21 DefaultMutableTreeNode node1;//人员基本信息维护 22 DefaultMutableTreeNode node2;//部门信息管理 23 DefaultMutableTreeNode node3;//人员调动管理 24 DefaultMutableTreeNode node4;//人员考核管理 25 DefaultMutableTreeNode node5;//劳资管理 26 DefaultMutableTreeNode leafnode; 27 TreePath treePath; 28 29 //主界面面板 30 public static JSplitPane splitPane; 31 JPanel panel1; 32 JPanel panel2; 33 JPanel panel3; 34 JLabel welcome = new JLabel(); 35 JScrollPane scrollPane; 36 /** 37 * 程序初始化函数 38 */ 39 public HrMain() 40 { 41 enableEvents(AWTEvent.WINDOW_EVENT_MASK); 42 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 43 this.pack(); 44 this.setSize(faceSize); 45 this.setTitle("人事管理系统"); 46 icon = getImage("icon.png"); 47 this.setIconImage(icon);//设置程序图标 48 this.setResizable(false); 49 try{ 50 Init(); 51 } 52 catch(Exception e){ 53 e.printStackTrace(); 54 } 55 } 56 /** 57 * 程序初始化函数 58 */ 59 private void Init() throws Exception 60 { 61 //添加JTree菜单 62 root = new DefaultMutableTreeNode("人事管理系统"); 63 node1 = new DefaultMutableTreeNode("基本信息管理"); 64 node2 = new DefaultMutableTreeNode("人员调动管理"); 65 node3 = new DefaultMutableTreeNode("人员考核管理"); 66 node4 = new DefaultMutableTreeNode("劳资管理"); 67 //人员基本信息 68 root.add(node1); 69 leafnode = new DefaultMutableTreeNode("添加人员信息"); 70 node1.add(leafnode); 71 leafnode = new DefaultMutableTreeNode("修改人员信息"); 72 node1.add(leafnode); 73 leafnode = new DefaultMutableTreeNode("删除人员信息"); 74 node1.add(leafnode); 75 leafnode = new DefaultMutableTreeNode("查询人员信息"); 76 node1.add(leafnode); 77 leafnode = new DefaultMutableTreeNode("部门管理"); 78 node1.add(leafnode); 79 //人员调动 80 root.add(node2); 81 leafnode = new DefaultMutableTreeNode("人员调动"); 82 node2.add(leafnode); 83 leafnode = new DefaultMutableTreeNode("调动历史查询"); 84 node2.add(leafnode); 85 //人员考核管理 86 root.add(node3); 87 leafnode = new DefaultMutableTreeNode("人员考核"); 88 node3.add(leafnode); 89 leafnode = new DefaultMutableTreeNode("考核历史查询"); 90 node3.add(leafnode); 91 //劳资管理 92 root.add(node4); 93 leafnode = new DefaultMutableTreeNode("劳资分配管理"); 94 node4.add(leafnode); 95 leafnode = new DefaultMutableTreeNode("劳资历史查询"); 96 node4.add(leafnode); 97 //生成左侧的JTree 98 tree = new JTree(root); 99 scrollPane = new JScrollPane(tree); 100 scrollPane.setPreferredSize(new Dimension(150,400)); 101 tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); 102 //生成JPanel 103 panel1 = new JPanel(); 104 panel2 = new JPanel(); 105 panel3 = new JPanel(); 106 panel1.add(scrollPane); 107 welcome.setText("欢迎使用人事管理系统"); 108 welcome.setFont(new Font("Dialog",0,16)); 109 panel3.add(welcome); 110 //生成JSplitPane并设置参数 111 splitPane = new JSplitPane(); 112 splitPane.setOneTouchExpandable(false); 113 splitPane.setContinuousLayout(true); 114 splitPane.setPreferredSize(new Dimension(150,400)); 115 splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT); 116 splitPane.setLeftComponent(panel1); 117 splitPane.setRightComponent(panel3); 118 splitPane.setDividerSize(2); 119 splitPane.setDividerLocation(161); 120 //生成主界面 121 this.setContentPane(splitPane); 122 this.setVisible(true); 123 //添加事件侦听 124 tree.addTreeSelectionListener(this); 125 //关闭程序时的操作 126 this.addWindowListener( 127 new WindowAdapter(){ 128 public void windowClosing(WindowEvent e){ 129 System.exit(0); 130 } 131 } 132 ); 133 } 134 /** 135 * 事件处理 136 */ 137 public void actionPerformed(ActionEvent e){ 138 139 } 140 /** 141 * JTree事件处理 142 */ 143 public void valueChanged(TreeSelectionEvent tse) 144 { 145 DefaultMutableTreeNode dnode = (DefaultMutableTreeNode)tse.getPath().getLastPathComponent(); 146 System.out.println("dnode="+dnode); 147 String node_str = dnode.toString(); 148 if(node_str == "人事管理系统"){ 149 splitPane.setRightComponent(panel3); 150 } 151 //人员基本信息树 152 else if(node_str == "基本信息管理"){ 153 //当选中后展开或关闭叶子节点 154 treePath = new TreePath(node1.getPath()); 155 if(tree.isExpanded(treePath)) 156 tree.collapsePath(treePath); 157 else 158 tree.expandPath(treePath); 159 } 160 else if(node_str == "添加人员信息"){ 161 Node11Panel node11Panel = new Node11Panel(); 162 splitPane.setRightComponent(node11Panel); 163 } 164 else if(node_str == "修改人员信息"){ 165 Node12Panel node12Panel = new Node12Panel(); 166 splitPane.setRightComponent(node12Panel); 167 } 168 else if(node_str == "删除人员信息"){ 169 Node13Panel node13Panel = new Node13Panel(); 170 splitPane.setRightComponent(node13Panel); 171 } 172 else if(node_str == "查询人员信息"){ 173 Node14Panel node14Panel = new Node14Panel(); 174 splitPane.setRightComponent(node14Panel); 175 } 176 else if(node_str == "部门管理"){ 177 Node15Panel node15Panel = new Node15Panel(); 178 splitPane.setRightComponent(node15Panel); 179 } 180 //人员调动管理树 181 else if(node_str == "人员调动管理"){ 182 //当选中后展开或关闭叶子节点 183 treePath = new TreePath(node2.getPath()); 184 if(tree.isExpanded(treePath)) 185 tree.collapsePath(treePath); 186 else 187 tree.expandPath(treePath); 188 } 189 else if(node_str == "人员调动"){ 190 Node21Panel node21Panel = new Node21Panel(); 191 splitPane.setRightComponent(node21Panel); 192 } 193 else if(node_str == "调动历史查询"){ 194 Node22Panel node22Panel = new Node22Panel(); 195 splitPane.setRightComponent(node22Panel); 196 } 197 //人员考核管理树 198 else if(node_str == "人员考核管理"){ 199 //当选中后展开或关闭叶子节点 200 treePath = new TreePath(node3.getPath()); 201 if(tree.isExpanded(treePath)) 202 tree.collapsePath(treePath); 203 else 204 tree.expandPath(treePath); 205 } 206 else if(node_str == "人员考核"){ 207 Node31Panel node31Panel = new Node31Panel(); 208 splitPane.setRightComponent(node31Panel); 209 } 210 else if(node_str == "考核历史查询"){ 211 Node32Panel node32Panel = new Node32Panel(); 212 splitPane.setRightComponent(node32Panel); 213 } 214 //劳资管理树 215 else if(node_str == "劳资管理"){ 216 //当选中后展开或关闭叶子节点 217 treePath = new TreePath(node4.getPath()); 218 if(tree.isExpanded(treePath)) 219 tree.collapsePath(treePath); 220 else 221 tree.expandPath(treePath); 222 } 223 else if(node_str == "劳资分配管理"){ 224 Node41Panel node41Panel = new Node41Panel(); 225 splitPane.setRightComponent(node41Panel); 226 } 227 else if(node_str == "劳资历史查询"){ 228 Node42Panel node42Panel = new Node42Panel(); 229 splitPane.setRightComponent(node42Panel); 230 } 231 } 232 /** 233 * 通过给定的文件名获得图像 234 */ 235 Image getImage(String filename) 236 { 237 URLClassLoader urlLoader = (URLClassLoader)this.getClass().getClassLoader(); 238 URL url = null; 239 Image image = null; 240 url = urlLoader.findResource(filename); 241 image = Toolkit.getDefaultToolkit().getImage(url); 242 MediaTracker mediatracker = new MediaTracker(this); 243 try{ 244 mediatracker.addImage(image, 0); 245 mediatracker.waitForID(0); 246 } 247 catch(InterruptedException _ex){ 248 image = null; 249 } 250 if(mediatracker.isErrorID(0)){ 251 image = null; 252 } 253 return image; 254 } 255 }
以上是关于Java课程设计——人事管理系统的主要内容,如果未能解决你的问题,请参考以下文章
基于java的企业人事管理系统设计--软件工程课程设计(含源码与论文设计).rar