1、基于Java的企业员工车辆信息管理系统实验报告Java考核 课程名称 Java程序设计 题目名称 企业车辆信息管理系统 学生学院 计算机 专业班级 学 号 学生姓名 指导教师 2015年 11 月 27 日难度系数独立完成工作量占总工作量的比例程序功能完成情况报告内容与格式总评成绩一、题目要求编程实现一个简单的企业车辆信息管理系统,使其可以对员工信息进行存储,修改查询等功能。二、程序界面主界面:删除员工记录窗口界面:添加员工记录窗口界面:查看所有员工信息窗口界面:查询修改员工信息界面:三、源代码主窗口界面代码:package com.easen;import java.awt.BorderLa
2、yout;import java.awt.Color;import java.awt.Font;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;public class Main public static void main(String args) new MyFrame(); /初始界面设计class MyFrame extends JFrame implements ActionListener JPanel jp = new JPanel(); JM
3、enuItem add = new JMenuItem(添加员工记录); JMenuItem alter = new JMenuItem(查询并修改员工信息); JMenuItem search = new JMenuItem(查看员工信息); JMenuItem delete = new JMenuItem(删除员工记录); JMenuItem quit = new JMenuItem(退出); MyFrame() /设置窗体信息 JFrame jf = new JFrame(); jf.setTitle(员工信息管理系统); jf.setBounds(400, 100, 400, 400)
4、; /设置菜单条 JMenuBar jb = new JMenuBar(); jf.setJMenuBar(jb); JLabel jl = new JLabel(欢迎来到员工信息管理系统,JLabel.CENTER); jl.setFont(new Font(宋体,Font.BOLD,30); jl.setForeground(Color.BLUE); jp.setLayout(new BorderLayout(); jp.add(Center,jl); /加菜单并添加监听器 JMenu menu = new JMenu(菜单选项); menu.add(add).addActionListe
5、ner(this); menu.add(alter).addActionListener(this); menu.add(search).addActionListener(this); menu.add(delete).addActionListener(this); menu.add(quit).addActionListener(this); jb.add(menu); jf.setVisible(true); jf.add(jp); jp.setBackground(Color.YELLOW); jf.setDefaultCloseOperation(EXIT_ON_CLOSE); /
6、重写监听器方法 Override public void actionPerformed(ActionEvent e) if(e.getSource() = add) add(); else if(e.getSource() = alter) alter(); else if(e.getSource() = delete) delete(); else if(e.getSource() = search) search(); else if(e.getSource() = quit) System.exit(0); /调用查看窗口 private void search() Searchfra
7、me searchframe = new Searchframe(); searchframe.setVisible(true); /调用删除窗口 private void delete() Deleteframe deleteframe = new Deleteframe(); deleteframe.setVisible(true); /调用修改窗口 private void alter() Alterframe alterframe = new Alterframe(); alterframe.setVisible(true); /调用增加记录窗口 private void add()
8、Addframe addframe = new Addframe(); addframe.setVisible(true); 添加员工信息界面代码:package com.easen;import java.awt.Checkbox;import java.awt.CheckboxGroup;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.I
9、temListener;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLException;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTextField;class Addframe extends JFrame implements ActionListener, ItemListener /
10、设置画板 JPanel jp1 = new JPanel(); JPanel jp2 = new JPanel(); JPanel jp3 = new JPanel(); JPanel jp4 = new JPanel(); JPanel jp5 = new JPanel(); JPanel jp6 = new JPanel(); JPanel jp7 = new JPanel(); JPanel jp8 = new JPanel(); JPanel jp9 = new JPanel(); JPanel jp10 = new JPanel(); /设置提示标签 JLabel jl_name =
11、 new JLabel(员工姓名); JLabel jl_number = new JLabel(员工工号); JLabel jl_sex = new JLabel(性别); JLabel jl_age = new JLabel(年龄); JLabel jl_vehicle = new JLabel(有无车:); JLabel jl_brand = new JLabel(车型号); JLabel jl_color = new JLabel(颜色); JLabel jl_licenceplate = new JLabel(车牌号); JLabel suggest = new JLabel();
12、JLabel jl_yes = new JLabel(有); JLabel jl_no = new JLabel(无); /设置可输入的单行文本域 JTextField jt_name = new JTextField(,10); JTextField jt_number = new JTextField(,10); JTextField jt_sex = new JTextField(,10); JTextField jt_age = new JTextField(,10); JTextField jt_brand = new JTextField(,10); JTextField jt_c
13、olor = new JTextField(,10); JTextField jt_licenceplate = new JTextField(,10); /设置添加返回等按钮 JButton add = new JButton(添加); JButton reset = new JButton(重置); JButton back = new JButton(返回); /设置单选框 CheckboxGroup cbg = new CheckboxGroup(); Checkbox yes = new Checkbox(,cbg,false); Checkbox no = new Checkbox
14、(,cbg,false); Addframe() /设置网格布局以及大小 setTitle(添加员工记录); setLayout(new GridLayout(10, 1); setBounds(200, 0, 800, 800); /将组件添加至画板中 jp1.add(jl_name); jp1.add(jt_name); jp2.add(jl_number); jp2.add(jt_number); jp3.add(jl_sex); jp3.add(jt_sex); jp4.add(jl_age); jp4.add(jt_age); jp5.add(jl_vehicle); jp5.add
15、(yes); jp5.add(jl_yes); jp5.add(no); jp5.add(jl_no); jp6.add(jl_brand); jp6.add(jt_brand); jp7.add(jl_color); jp7.add(jt_color); jp8.add(jl_licenceplate); jp8.add(jt_licenceplate); /为按钮及单选框添加监听器 add.addActionListener(this); reset.addActionListener(this); back.addActionListener(this); yes.addItemList
16、ener(this); no.addItemListener(this); jp9.add(add); jp9.add(reset); jp9.add(back); jp10.add(suggest); add(jp1); add(jp2); add(jp3); add(jp4); add(jp5); add(jp6); add(jp7); add(jp8); add(jp9); add(jp10); /重写监听器方法 Override public void actionPerformed(ActionEvent e) if(e.getSource() = add) add(); else
17、if(e.getSource() = back) back(); else if(e.getSource() = reset) reset(); /重置 private void reset() jt_name.setText(); jt_number.setText(); jt_age.setText(); jt_sex.setText(); jt_brand.setText(); jt_color.setText(); jt_licenceplate.setText(); suggest.setText(); /返回 private void back() setVisible(false
18、); /添加 private void add() try /判断信息是否输入完整 if(jt_name.getText().equals() | jt_age.getText().equals() | jt_number.getText().equals() | jt_sex.getText().equals() suggest.setText(请完善员工信息!); else if(yes.getState() & (jt_brand.getText().equals() | jt_color.getText().equals() | jt_licenceplate.getText().eq
19、uals() suggest.setText(请完善车辆信息!); else String vehicle = ; if(yes.getState() vehicle = 有; else if(no.getState() vehicle = 无; Connection con = Sql_connection.getConnection(); java.sql.Statement sql = con.createStatement(); String query = select * from message; ResultSet result = sql.executeQuery(query
20、); while(result.next() if(result.getString(number).equals(jt_number.getText() suggest.setText(该工号已存在,请重新输入一个工号!); return; sql.executeUpdate(insert message values(+jt_name.getText()+,+jt_number.getText()+,+jt_sex.getText()+,+jt_age.getText()+,+vehicle+,+jt_brand.getText()+,+jt_color.getText()+,+jt_li
21、cenceplate.getText()+); suggest.setText(添加成功!); sql.close(); con.close(); catch (ClassNotFoundException | SQLException e) e.printStackTrace(); /重写单选框的监听器方法 Override public void itemStateChanged(ItemEvent e) if(no.getState() jt_brand.setText(); jt_color.setText(); jt_licenceplate.setText(); jt_brand.
22、setEditable(false); jt_color.setEditable(false); jt_licenceplate.setEditable(false); else jt_brand.setEditable(true); jt_color.setEditable(true); jt_licenceplate.setEditable(true); 修改查询员工信息界面代码:package com.easen;import java.awt.Checkbox;import java.awt.CheckboxGroup;import java.awt.GridLayout;import
23、 java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLException;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import
24、javax.swing.JPanel;import javax.swing.JTextField;class Alterframe extends JFrame implements ActionListener, ItemListener /设置画板 JPanel jp0 = new JPanel(); JPanel jp1 = new JPanel(); JPanel jp2 = new JPanel(); JPanel jp3 = new JPanel(); JPanel jp4 = new JPanel(); JPanel jp5 = new JPanel(); JPanel jp6
25、= new JPanel(); JPanel jp7 = new JPanel(); JPanel jp8 = new JPanel(); JPanel jp9 = new JPanel(); JPanel jp10 = new JPanel(); /设置提示标签 JLabel jl_enter = new JLabel(请输入工号); JLabel jl_name = new JLabel(员工姓名); JLabel jl_sex = new JLabel(性别); JLabel jl_age = new JLabel(年龄); JLabel jl_vehicle = new JLabel(
26、有无车:); JLabel jl_brand = new JLabel(车型号); JLabel jl_color = new JLabel(颜色); JLabel jl_licenceplate = new JLabel(车牌号); JLabel suggest = new JLabel(); JLabel jl_yes = new JLabel(有); JLabel jl_no = new JLabel(无); /设置可输入的单行文本域 JTextField jt_enter = new JTextField(,10); JTextField jt_name = new JTextFiel
27、d(,10); JTextField jt_sex = new JTextField(,10); JTextField jt_age = new JTextField(,10); JTextField jt_brand = new JTextField(,10); JTextField jt_color = new JTextField(,10); JTextField jt_licenceplate = new JTextField(,10); /设置修改返回等按钮 JButton search = new JButton(查询); JButton alter = new JButton(修
28、改); JButton reset = new JButton(清空); JButton back = new JButton(返回); /设置单选框 CheckboxGroup cbg = new CheckboxGroup(); Checkbox yes = new Checkbox(,cbg,false); Checkbox no = new Checkbox(,cbg,false); Alterframe() /设置网格布局以及大小 setTitle(查询并修改员工信息); setLayout(new GridLayout(10, 1); setBounds(200, 0, 800, 800); /将组件添加至画板中 jp0.add(jl_enter); jp0.add(jt_enter); jp0.add(search); jp1.add(jl_name); jp1.add(jt_name); jp3.add(jl_sex);
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1