面向对象课程设计报告----实验室设备管理系统.docx
面向对象课程设计报告实验室设备管理系统任务分配及完成情况姓名承担任务自评成绩郑雄风代码部分、调试测试。优汤晨煜整体框架、报告撰写优实验室设备管理系统设计报告1课程设计任务概述目的:完成一份管理实验室设备的软件。主要完成的任务:对实验室设备进行系统化管理。功能模块:用户管理,合法用户许可访问;A信息录入,包括记录的追加和插入; 信息删除; 信息修改; 信息排序和查询; 数据的导入/导出; 简单的帮助。2系统分析与建模2.1系统功能分析1主界面,包含所有功能的集合2用户等陆,分为两个功能。用户登录和用户查询,其中用户登陆是通过输入用户名和密码进行登陆,用户注册是自己设定用户和密码。3查询,直接进行查询信息,但是无法进行修改和删除等功能。4设备管理,分为管理和添加两个功能。其中添加包括设备编号,设备名称,设备状态,制造商,购买状态。管理分为查询和删除两个功能,可以通过设备编号和设备名称来查找。5系统管理,分为保存,导入,导出。退出功能。保存是将信息录入,导入是导入文件,导出是导出文件,退出是直接退出主界面。5帮助是关于系统和联系作者。2.2用例图及用例说明2.1.1管理员登陆用例(I)管理员登陆用例描述UseCase名称登陆执行者管理员事件流A输入用户名B输入密码C若密码不正确无法登陆D若无用户名新增管理员后置条件若新增用户正确,则增加管理员新的用户及密码(2)管理员登陆用例图2.1.2管理员对实验设备添加用例(1)管理员对实验设备添加用例描述UseCase名称设备添加执行者管理员事件流A选择添加功能B添加设备编号C添加设备名称D设备状态E制造商F购买状态后置条件系统更新数据库(2)管理员对实验设备添加用例图2.1.3管理员对实验设备管理用例(I)管理员对实验设备管理用例描述UseCase名称设备管理执行者管理员事件流A选择查询还是删除B删除C选择排序D选择设备编号还是设备名称后置条件系统更新数据库(2)管理员对实验设备管理用例图2.1.4管理员对系统管理用例(1)管理员对系统管理用例描述UseCase名称系统管理执行者管理员事件流A选择功能B保存所有操作C导入文件D导出文件E退出后置条件系统更新数据库(2)管理员对系统管理用例图2.1.5整体用例框图3系统设计3.1系统类图Devicednum:Stringdname:Stringindustry:Stringindate:Stringdtime:String+Device(dnum:String,dname:String,industry:String,indate:String,dtime:String)+IoStringO:String+DeviceO+getDnameO:String+setDname(dname:String):void+getDnumO:String+setDnum(dnum:String):void+getDtimeO:String+setDtime(dtime:String):void+getlndustry:String+setlndustry(industry:String):void+getlndate:String+setlndate(indate:String):void+writebject(out:ObjectOutputStream):void+readbject(in:ObjectInputStream):void设备类C()User+username:Stringpassword:String+getUsernameO:String÷setUsername(username:String):void+getPasswordO:String+setPassword(password:String):void+User(username:String,password:String)+writebject(out:ObjectOutputStream):void+readbject(in:ObjectInputStream):void用户类JDBCUtiles-DBDRVER:String-USER:StringURL:SMnrPASSWORD:Strmg+getConnectionO:COnneCtion+release(stmt:StatementrS:ReSUltSeLCOnn:COnneCtion):Void+release(stmt:Statement,Conn:ConneCtion):VOid<数据库类3.2系统活动图 删除 3. 3系统时序图,介比O“Q¾fr 估 ZO日术成助04'02.1 F鼬川厂'。;口0用户操作21史上a;h.;©.o3"Q%f.iSO,通拧孤立:2任”;息0»14:能泣C任Qn()5:保。0、51ThtG彳f.;FO5.11也”;2备“总0用户对设备信息修改操作4系统实现/*用户界面*/packageUI;importjava.awt.BorderLayout;importjava.awt.EventQueue;importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.border.EmptyBorder;importjavax.swing.JMenuBar;importjavax.swing.JMenu;importjavax.swing.JMenuItem;importjava.awt.event.ActionListener;importjava.awt.evenl.ActionEvent;publicclassFirstMenuextendsJFrameprivateJPanelContentPane;*Launchtheapplication.*/publicstaticvoidmain(Stringargs)EventQueue.invokeLater(newRunnable()publicvoidrun()try(FirstMenuframe=newFirstMenu();frame.setVisibIe(true);)catch(Exceptione)e.printStackTrace();1)1);*Createtheframe.*/publicFirstMenuOsetDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setBounds(100,100,800,500);ContentPane=newJPanel();contentPane.setBorder(newEmptyBorder(5,5,5,5);SetContentPane(ContentPane);contentPane.setLayout(null);JMenuBartnenuBar=newJMenuBar();menuBar.setBounds(10,0,844,21);contentPane.add(menuBar);JMenumenu=newJMenu("u7528u6237u9009u62E9");menuBar.add(menu);JMenuItemmenuitem=newJMenuItem("u7528u6237u767Bu5F55");menuitem.addActionListener(newActionListenerOpublicvoidactionPerformed(ActionEvente)UserLoginO;)1);menu.add(menultem);JMenuItemmntmNewMenuItem=newJMenuItem("u7528u6237u6CE8u518C");mntmNewMenuItem.addActionListener(newActionListenerOpublicvoidactionPerformed(ActionEvente)AddUser();1);menu.add(mntmNewMenuItem);JMenumenu_2=newJMenu(,u8BBEu5907u67E5u8BE2");menuBar.add(menu_2);JMenuItemmenultem_l=newJMenuItem(,u67E5u8BE2");menultem_I.addActionListener(newActionListenerO(publicvoidactionPerfbrmed(ActionEvente)Deviced();)1);menu_2.add(menultem_1);1publicvoidUserLoginOUserLoginuserlogin=newUserLogin();userlogin.show();2publicvoidAddUser()UserAdduseradd=newUserAdd();useradd.show();3protectedvoidDeviced()/TODOAuto-generatedmethodstubDeviceddeviced=null;try(deviced=newDeviced();Icatch(ClassNotFoundExceptione)/TODO自动生成的catch块e.printStackTrace();)deviced.show();*用户操作界面*/packageUI;importjava.awt.EventQueue;importjava.awt.FileDialog;importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.JMenuBar;importjavax.swing.JMenu;importjavax.swing.JMenultem;importjavax.swing.JOptionPane;importjavax.swing.KeyStroke;importservice.DeviceService;importjava.awt.event.*;importjava.util.Vector;importjavax.swing.JTextFieId;importjava.awt.*;importjava.io.IOException;publicclassMenuextendsJFrameimplementsActionListenerIprivateJPanelContentPane;privateJMenuItemexitsystem;privateJMenuItemreservefile;privateJMenuItemadduser;privateJMenuItemuserin;privateJMenuItemsort;privateJMenuItemsearch;privateJMenuItemaboutsystem;privateJMenuItemcontactworker;privateJMenuhelp;privateJMenuloginuser;privateJMenudeviceinfb;privateJMenudeviceadd;privateJMenudevicedel;privateJMenusystem;privateJMenudevicemanange;privateDeviceServicedeviceservice;Vector<Menu>vector=newVector();privateJTextFieIdUsertextField=null;*Launchtheapplication.*/publicstaticvoidmain(Stringargs)EventQueue.invokeLater(newRunnable()publicvoidrun()try(Menuframe=newMenu();frame.setVisibIe(true);)catch(Exceptione)e.printStackTrace();1)1);*Createtheframe.*/publicMenu()setTitle(,u5B9Eu9A8Cu5BA4u8BBEu5907u7BAlu7406u7CFBu7EDF");setDefaultCloseOperation(Menu.EXIT_ON_CLOSE);setBounds(100,100,800,500);JMenuBarmenuBar=newJMenuBar();setJMenuBar(menuBar);JMenusystem=newJMenU("系统管理");menuBar.add(system);JMenuItemreservefile=newJMenUItem("保存");reservefile.addActionListener(this);system.add(reservefile);reservefile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,lnputEvent.CTRL_MASK);JMenuItemexitsystem=newJMenUItem("退出");exitsystem.addActionListener(newActionListenerOpublicvoidactionPerformed(ActionEvente)dispose(););JMenuItemmenultemjmport=newJMenuItem(',u5BFCu5165");menuItemJmport.addActionListener(newActionListenerOpublicvoidactionPerformed(ActionEventarg)importFromFile();)1);system.add(menultemjnport);JMenuItemmenultem_export=newJMenuItem(',u5BFCu51FAn);menuItem_export.addActionListener(newActionListenerO(publicvoidactionPerformed(ActionEventarg)try(exportToFile();)catch(IOExceptione)/TODOAuto-generatedcatchblocke.printStackTrace();1)1);system.add(menultem_export);system.add(exitsystem);JMenudevicemanange=newJMenU("设备管理");menuBar.add(devicemanange);JMenuItemmenultem_manager=newJMenUltem("管理”);menuItem_manager.addActionListener(newActionListenerOpublicvoidactionPerformed(ActionEvente)DeleteDeviceO;)1);devicemanange.add(menultem_manager);JMenuItemmenuitem=newJMenUItem("添力);menuitem.addActionListener(newActionListenerOpublicvoidactionPerformed(ActionEvente)AddDevice();)1);devicemanange.add(menultem);JMenuhelp=newJMenU("帮助");menuBar.add(help);JMenuItemaboutsystem=newJMenUItem("关于系统");help.add(aboutsystem);aboutsystem.addActionListener(this);JMenuItemcontactworker=newJMenUltem("联系作者”);help.add(contactworker);contactworker.addActionListener(this);ContentPane=newJPanel();contentPane.setBorder(null);SetContentPane(ContentPane);contentPane.setLayout(null);1protectedvoidDeIeteDeviceO/TODOAuto-generatedmethodstubDeviceDetaiIdevicedelete=null;try(devicedelete=newDeviceDetailO;)catch(ClassNotFoundExceptione)(/T0D0自动生成的catch块e.printStackTrace();)devicedelete.show();1publicvoidAddDeviceO/TODOAuto-generatedmethodstubAddDeviceadddevice=newAddDevice();adddevice.show();1voidinit(Strings)SetTitIe("实验室设备管理系统”);OverridepublicvoidactionPerfrmed(ActionEvente)/T0D0自动生成的方法存根Stringcmd=e.getActionCommand();if(cmd.equals("保存")JoPtiOnPane.showMessageDialog(this,"己保存所有数据");if(Cmd.equals,关于系统")JoPtionPane.showMessageDialog(this,"本系统主题为“水墨书乡”,以墨色为主色调,避免纷繁多杂的视觉冲击,”+”其界面整洁有序,更彰显文化的古韵魅力。n操作上人性化设计:nl.本软件操作效率较高。52.”+”实用性强:包含设备管理最核心基础的功能,反应速度快!适用于一般的个人、学校、企业的应用。+”n3.本版本为预览版”);)if(cmd.equals("联系作者”)(JOPtiOnPane.showMessageDialog(this,"作者:冷月n"+"QQ:1014539765");)protectedvoidimportFromFile()StringfileName=null;使用文件打开对话框,取得用户输入的需保存的文件位置及文件名,见教材“Java2实用教程"P18<>FileDiaIogfileDialog_open=newFileDialog(this,"打开文件对话框",FileDialog,LOAD);fileDialog_open.setVisible(true);fileName=fileDialog_open.getFile();如果用户单击“取消”按钮,值为null。if(fileName!=null)Stringpath=fileDialog_open.getDirectory()+fileName;文件的完整路径deviceservice.importFromFile(path);)1protectedvoidexportToFile()throwsIOExceptionStringfileName=null;使用文件打开对话框,取得用户输入的需保存的文件位置及文件名,见教材“Java2实用教程”PI8。FileDialogfileDialog_save=newFileDialog(this,"保存文件对话框",FileDialog,SAVE);fileDialog_save.setVisible(true);fileName=fileDialog_save.getFile();/如果用户单击“取消"按钮,值为nulLif(fileName!=null)Stringpath=fileDialog_save.getDirectory()+fileName;文件的完整路径deviceservice.exortToFile(path);*用户登录界面*/packageUI;importjava.awt.BorderLayout;importjava.awt.EventQueue;importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.border.EmptyBorder;importjavax.swing.JOptionPane;importjavax.swing.JButton;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.MouseAdapter;importjava.awt.event.MouseEvent;importjavax.swing.JLabel;importjava.awt.Font;importjavax.swing.JTextField;importservice.DeviceService;importuser.User;importjavax.swing.JPasswordField;SUPPreSSWarningS("serial")classUserLoginextendsJFrameprivateJPaneluserlogin;privateJTextFieIdusnamefield;privateJPasswordFieldpasswordfield;*Launchtheapplication.*/publicstaticvoidmain(Stringargs)EventQueue.invokeLater(newRunnable()publicvoidrun()(try(UserLoginframe=newUserLogin();frame.setVisible(true);catch(Exceptione)e.printStackTrace();1)1);* Createtheframe.* paramtitle* Paramvector* /UserLoginOsetBounds(100,100,288,228);userlogin=newJPanel();userlogin.setBorder(newEmptyBorder(5,5,5,5);SetContentPane(Userlogin);userlogin.setLayout(null);JLabelusername=newJLabel("u7528u6237u540D);username.setFont(newFonK"隶书",Font.BOLD,14);username.setBounds(28,29,54,23);userlogin.add(username);JLabelpassword=newJLabel("u5BC6u7801");password.setFont(newFonK"隶书",Font.BOLD,14);password.setBounds(28,72,54,23);userlogin.add(password);Usnamefield=newJTextFieIdO;usnamefield.setBounds(107,29,117,23);userlogin.add(usnamefield);usnamefield.setColumns(10);passwordfield=newJPasswordField();passwordfield.setColumns(10);passwordfield.setBounds(107,72,117,23);userlogin.add(passwordfield);JButtonbutton_ok=newJBUttOn("u767Bu5F55");button_ok.addActionListener(newActionListenerOpublicvoidactionPerformed(ActionEvente)Stringusername=usnamefield.getText().trim();Stringpassword=passwordfield.getText().trim();if(usnamefield.getText().equals(",)JoPtionPane.showMessageDiak)g(nun,"用户名不可为空,请确认!");return;)if(passwordfield.getText().equals(,)JOPtionPane.showMessageDiak)g(nu11,"密码不可为空!");return;)Useruser=newUser(usemame,password);if(DeviceService.Logon(User)!=null)JOPtionPane.showMessageDialog(null,"登陆成功");setVisible(false);Menumenu=newMenu();menu.setVisible(true);)elseJOPtiOnPane.showMessageDialog(null,"密码或者用户名出错!,);setVisible(true);clear();)1);button_ok.setBounds(41,132,66,23);userlogin.add(button_ok);JButtonbutton_cancel=newJButton("u53D6u6D88");button_cancel.addMouseListener(newMouseAdapterO©OverridepublicvoidmouseClicked(MouseEvente)dispose(););button_cancel.setBounds(173,132,66,23);userlogin.add(button_cancel);1protectedvoidclear()/TODO自动生成的方法存根usnamefield.setText("");PaSSWordfieId.setText("");/*管理界面*/packageUI;importjava.awt.EventQueue;importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.border.EmptyBorder;importjavax.swing.JComboBox;importjavax.swing.DefaultcomboBoxModel;importjavax.swing.JOptionPane;importjavax.swing.JTextField;importjavax.swing.JScrollPane;importjavax.swing.JTable;importjavax.swing.table.DefaultTableModel;importjavax.swing.JButton;importjavax.swing.JLabel;importjavax.swing.SwingConstants;importservice.DeviceService;importuser.Device;importjava.awt.event.*;importjava.io.BufferedReader;importjava.io.DataOutputStream;importjava.io.File;importjava.io.FilelnputStream;importjava.io.FileOutputStream;importjava.io.FileReader;importjava.io.IOException;importjava.io.ObjectlnputStream;importjava.io.ObjectOutputStream;importjava.util.ArrayList;importjava.util.Iterator;importjava.util.LinkedList;importjava.util.List;publicclassDeviceDetailextendsJFrameimplementsItemListener,ActionListenerprivateJPanelContentPane;privateJScrollPanescrollPane;privateJTableinfo;privateJComboBoxcomboBox;privateJTextFieIddnumfield;privateList<Device>devicelist;ObjectJJobject;Filefile=newFile("devices.txt,');privateJTextFieIddnamefield;privateJLabelIbinfb;/Vector<Device>vector2;* Launchtheapplication.* /publicstaticvoidmain(Stringargs)EventQueue.invokeLater(newRunnable()publicvoidrun()try(DeviceDetaiIframe=newDeviceDetailO;frame.setVisible(true);)catch(Exceptione)e.printStackTrace();1)1);* Createtheframe.* throwsClassNotFoundException* /SUPPreSSWarningS("unchecked")publicDeviceDetailOthrowsClassNotFoundException/super(s);setTitle(,u8BBEu5907u7BAlu7406");setDefaultCloseOperation(JFrame.D!SPOSE_ON_CLOSE);setBounds(100,100,692,437);ContentPane=newJPanel();contentPane.setBorder(newEmptyBorder(5,5,5,5);SetContentPane(ContentPane);contentPane.setLayout(null);ComboBox=newJComboBox();ConiboBox.add!temListener(this);”删除comboBox.setModel(newDefaultComboBoxModel(newString,'查询",");CombOBOX.setBounds(32,46,91,21);contentPane.add(comboBox);Ibinfo=newJLabel('n');Ibinfo.setLabelFor(this);lbinfo.setEnabled(false);lbinfo.setBounds(32,78,209,26);contentPane.add(lbinfo);ScrollPane=newJScrollPane();scrollPane.setBounds(32,114,618,261);contentPane.add(scrollPane);info=newJTable();ScrollPane.setViewportView(infb);info.setModel(newDefaultTabIeModeKobject=newObjectnull,null,null,null,null),null,null,null,null,null),null,null,null,null,null),null,null,null,null,null),null,null,null,null,null),null,null,null,null,null),null,null,null,null,null),null,null,null,null,null),null,null,null,null,null),null,null,null,null,null),