




已阅读5页,还剩24页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
课 程 设 计 报 告学院、系:吉林大学珠海学院计算机科学与技术系专业名称:网络工程课程设计科目java程序课程设计学生姓名:王佳指导教师:吕健波完成时间:2010年9月-11月教师管理系统一、 设计任务与目标1)负责教师管理的主界面(用菜单方式打开下面的四个功能界面)录入教师管理的界面修改教师管理的界面查询教师管理的界面删除教师管理的界面2)教师数据表的字段要求至少包含:工号、姓名、年龄、职称、所在系、教授的主要课程、联系电话、联系地址等字段。要求字段类型设计合理、使用方便。3)要求界面美观大方、功能实现完整 此程序的设计,主要包括两个主体部分,一是界面部分,二是创建按钮并监听,实现录入,修改,查询,删除等功能。以前在C+编写过类似的教师管理系统,其主要思路和本题保持一致,但代码不同。需要准备的工作是创建主界面并完善各项分功能,连接数据库,实现录入和查看同步。此次设计将会提高我对真正的JAVA程序设计的实战能力,对以前学过的知识融会贯通,并且深化和应用。意在最终程序可以美观,实用,人性化,尽最大的能力扩充相关分模块。二、 方案设计与论证 针对这道设计题的特点,首先做一个界面,界面中包括相关的分功能,录入,修改,查询,删除等,用surface做界面,分别设置各自的监听器,监听每一个button,并且各个分功能是对应各自的类。这样的话,有利于用户提出不同修改的要求,此时只要单独修改个别类即可,提高程序的便捷化并且满足不同客户的需要。在做这道题时遇到最大的障碍就是连接access数据库,因为以前没学过,所以这部分知识完全不会,必须考自学。自己做这道题与其他设计人员最大的不同就在于将每个分功能,各自单独的写在一个类中,与把所有源代码都写在一个JAVA文件中的方法,更易于修改和编辑。三、 程序框图或流程图,程序清单与调用关系 教师信息管理系统主界面 Surface Ext(退出)Fin(查询)Del(删除)Chan(修改)Ads(录入)对数据库中的内容进行编辑Access数据库四、全部源程序清单package parent_window; /(package parent window包中的类)import java.awt.*;import javax.swing.*;import son_windows.*;public class surFace extends JFrameJButton findSt,addSt,chanSt,delSt,exitSt;/查找,添加,删除,退出/构造函数 public surFace() Container c=this.getContentPane(); c.setLayout(new GridLayout(2,1); JPanel lowerPanel=new JPanel(); c.setFont(new Font(plain,Font.PLAIN,13); JLabel label=new JLabel(欢迎进入教师信息管理系统,SwingConstants.CENTER); label.setFont(new Font(BOLD,Font.BOLD,30); c.add(label);/创建按钮 addSt=new JButton(录入); addSt.setToolTipText(添加教师信息); findSt=new JButton(查询); findSt.setToolTipText(查询信息); chanSt=new JButton(修改); chanSt.setToolTipText(修改成绩); delSt=new JButton(删除); delSt.setToolTipText(删除信息); exitSt=new JButton(退出); exitSt.setToolTipText(安全退出本系统); lowerPanel.add(findSt); lowerPanel.add(addSt); lowerPanel.add(chanSt); lowerPanel.add(delSt); lowerPanel.add(exitSt); c.add(lowerPanel);/注册监听器,新建独立监听器类 查找:fin(),添加:ads(),删除:del(),退出本体统:ext() findSt.addActionListener(new fin(); addSt.addActionListener(new ads(); chanSt.addActionListener(new cc(); /chanSt.addActionListener(new chan(); delSt.addActionListener(new del(); exitSt.addActionListener(new ext(); /main方法,实现主界面 public static void main (String args) surFace su=new surFace(); su.setSize(500,400); su.setTitle(欢迎使用教师管理系统!); su.setVisible(true); /*建立独立事件监听器类ads,处理surFace中“录入”点击事件*/package son_windows; /(package son_windows包中的类)(1)import java.awt.*;import javax.swing.*;import java.awt.event.*; import java.sql.*;public class ads extends JFrame implements ActionListener JTextField numberText,nameText,ageText,jobText,departmenText,classText,phoneText,addressText; JButton addButton,clearButton,closeButton; Container c2; JDialog jd; JDialog jd2;public ads() c2=this.getContentPane(); c2.setLayout(new GridLayout(3,1); JPanel p1=new JPanel(new GridLayout(8,2); JPanel p2=new JPanel(new FlowLayout(); / JLabel logoLabel=new JLabel(ii,SwingConstants.CENTER); logoLabel.setForeground(Color.black); logoLabel.setFont(new Font(TRUE,Font.TRUETYPE_FONT,20); logoLabel.setText(教师信息); c2.add(logoLabel); /创建JTextField numberText=new JTextField(); nameText=new JTextField(); ageText=new JTextField(); jobText=new JTextField(); departmenText=new JTextField(); classText=new JTextField(); phoneText=new JTextField(); addressText=new JTextField(); /添加JTextField p1.add(new JLabel(工号,SwingConstants.CENTER); p1.add(numberText); p1.add(new JLabel(姓名,SwingConstants.CENTER); p1.add(nameText); p1.add(new JLabel(年龄,SwingConstants.CENTER); p1.add(ageText); p1.add(new JLabel(职称,SwingConstants.CENTER); p1.add(jobText); p1.add(new JLabel(所在系,SwingConstants.CENTER); p1.add(departmenText); p1.add(new JLabel(主授课程,SwingConstants.CENTER); p1.add(classText); p1.add(new JLabel(联系电话,SwingConstants.CENTER); p1.add(phoneText); p1.add(new JLabel(联系地址,SwingConstants.CENTER); p1.add(addressText); c2.add(p1) ; / addButton=new JButton(添加); clearButton=new JButton(清除); closeButton=new JButton(退出); p2.add(addButton); p2.add(clearButton); p2.add(closeButton); c2.add(p2); this.setSize(500,400); this.setTitle(添加教师信息); /为添加按钮添加监听器(使用匿名内部类处理点击事件) addButton.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) String number,name,age,job,departmen,clas,phone,address; Statement stm; String str; int j=0; number=numberText.getText(); name=nameText.getText(); age=ageText.getText(); job=jobText.getText(); departmen=departmenText.getText(); clas=classText.getText(); phone=phoneText.getText(); address=addressText.getText(); str=insert into data1 values(+number+,+name+,+age+,+job+,+departmen+,+clas+,+phone+,+address+); if(number.equals()&name.equals()&age.equals()&job.equals()&departmen.equals()&clas.equals()&phone.equals()&address.equals() j=2;elsetry /加载驱动Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);/连接数据源forStuConnection con=DriverManager.getConnection(jdbc:odbc:forStu,);stm=con.createStatement();j=stm.executeUpdate(str); con.close(); catch (ClassNotFoundException e1) catch (SQLException e1) /jd=new JDialog();jd.setLayout(new GridLayout(2,1);jd.setSize(255,100);JPanel p1=new JPanel();JPanel p2=new JPanel();jd.add(p1);jd.add(p2);JLabel jl=new JLabel(添加成功!);JLabel jl2=new JLabel(不能添加空数据,请从新输入!);JLabel jl3=new JLabel(不能为相同数据,请从新输入!);JButton b=new JButton(确定);if(j=1)p1.add(jl);j=0;elseif(j=2)p1.add(jl2);elsep1.add(jl3);p2.add(b);jd.setVisible(true);b.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)jd.setVisible(false);); ); /添加“清除”键事件监听器 clearButton.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) numberText.setText(); nameText.setText(); ageText.setText(); jobText.setText(); departmenText.setText(); classText.setText(); phoneText.setText(); addressText.setText(); ); /添加“关闭窗口”按钮事件监听器 closeButton.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) ads.this.setVisible(false); ads.this.dispose(); );/新建类ads的actionPerformed方法,实现surFace中的录入事件界面public void actionPerformed(ActionEvent e)ads a=new ads();a.setVisible(true); (2)import java.awt.*;import java.awt.event.*;import javax.swing.*;public class cc extends JFrame implements ActionListenerContainer c1;public cc()c1=this.getContentPane();c1.setLayout(new GridLayout(4,1);JPanel jp1=new JPanel();JPanel jp2=new JPanel();JPanel jp3=new JPanel();JLabel jl=new JLabel(请选择要修改那种信息,SwingConstants.CENTER);jl.setFont(new Font(BOLD,Font.BOLD,30);c1.add(jl);JButton b1=new JButton(联系电话);JButton b2=new JButton(联系地址);JButton b3=new JButton( 取消 );jp1.add(b1);jp2.add(b2);jp3.add(b3);c1.add(jp1);c1.add(jp2);c1.add(jp3);b1.addActionListener(new chan_tel();b2.addActionListener(new chan_adr();b3.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)dispose(););public void actionPerformed(ActionEvent e)new cc();setSize(500,400);setVisible(true);(3)import java.awt.*;import java.awt.event.*;import java.sql.*;import javax.swing.*;public class chan_adr extends JFrame implements ActionListenerContainer c1;JPanel jp1,jp2,jp3,jp4;JLabel jl,jl2,jl3;JTextField jt1,jt2;JButton b1,b2,b3;JDialog jd;public chan_adr()c1=this.getContentPane();c1.setLayout(new GridLayout(4,1);jl=new JLabel(修改教师联系地址);jl.setFont(new Font(BOLD,Font.BOLD,30);jp1=new JPanel();jp2=new JPanel();jp3=new JPanel();jp4=new JPanel();jp1.add(jl);c1.add(jp1);jl2=new JLabel(教师工号:);jl3=new JLabel(联系地址:);jt1=new JTextField(10);jt2=new JTextField(10);jp2.add(jl2);jp2.add(jt1);jp3.add(jl3);jp3.add(jt2);c1.add(jp2);c1.add(jp3);b1=new JButton(确定);b2=new JButton(清除);b3=new JButton(退出);jp4.add(b1);jp4.add(b2);jp4.add(b3);c1.add(jp4);b1.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)Connection con=null;Statement st;String str=null;int i=0;tryClass.forName(sun.jdbc.odbc.JdbcOdbcDriver);con=DriverManager.getConnection(jdbc:odbc:forStu,);str=update data1 set 联系地址=+jt2.getText()+ where 工号=+jt1.getText()+;st=con.createStatement();i=st.executeUpdate(str);con.close();jd=new JDialog();jd.setVisible(true);jd.setLayout(new GridLayout(2,1);JPanel jpp1=new JPanel();JPanel jpp2=new JPanel();JLabel jll1=new JLabel(修改成功!);JLabel jll2=new JLabel(信息不存在,请核实后重试!);if(i=1)jpp1.add(jll1);elsejpp1.add(jll2);JButton jbb=new JButton(确定);jpp2.add(jbb);jd.add(jpp1);jd.add(jpp2);jd.setSize(255,100);jbb.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)jd.setVisible(false););catch(ClassNotFoundException e1)catch(SQLException e1);b2.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)jt1.setText();jt2.setText(););b3.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)setVisible(false);dispose(););public void actionPerformed(ActionEvent e)this.dispose();chan_adr c=new chan_adr();c.setSize(500,400);c.setVisible(true);(4)import java.awt.*;import java.awt.event.*;import java.sql.*;import javax.swing.*;public class chan_tel extends JFrame implements ActionListenerContainer c1;JPanel jp1,jp2,jp3,jp4;JLabel jl,jl2,jl3;JTextField jt1,jt2;JButton b1,b2,b3;JDialog jd;public chan_tel()c1=this.getContentPane();c1.setLayout(new GridLayout(4,1);jl=new JLabel(修改教师联系电话);jl.setFont(new Font(BOLD,Font.BOLD,30);jp1=new JPanel();jp2=new JPanel();jp3=new JPanel();jp4=new JPanel();jp1.add(jl);c1.add(jp1);jl2=new JLabel(教师工号:);jl3=new JLabel(联系电话:);jt1=new JTextField(10);jt2=new JTextField(10);jp2.add(jl2);jp2.add(jt1);jp3.add(jl3);jp3.add(jt2);c1.add(jp2);c1.add(jp3);b1=new JButton(确定);b2=new JButton(清除);b3=new JButton(退出);jp4.add(b1);jp4.add(b2);jp4.add(b3);c1.add(jp4);b1.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)Connection con=null;Statement st;String str=null;int i=0;tryClass.forName(sun.jdbc.odbc.JdbcOdbcDriver);con=DriverManager.getConnection(jdbc:odbc:forStu,);str=update data1 set 联系电话=+jt2.getText()+ where 工号=+jt1.getText()+;st=con.createStatement();i=st.executeUpdate(str);con.close();jd=new JDialog();jd.setVisible(true);jd.setLayout(new GridLayout(2,1);JPanel jpp1=new JPanel();JPanel jpp2=new JPanel();JLabel jll1=new JLabel(修改成功!);JLabel jll2=new JLabel(信息不存在,请核实后重试!);if(i=1)jpp1.add(jll1);elsejpp1.add(jll2);JButton jbb=new JButton(确定);jpp2.add(jbb);jd.add(jpp1);jd.add(jpp2);jd.setSize(255,100);jbb.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)jd.setVisible(false););catch(ClassNotFoundException e1)catch(SQLException e1);b2.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)jt1.setText();jt2.setText(););b3.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)setVisible(false);dispose(););public void actionPerformed(ActionEvent e)this.dispose();chan_tel c=new chan_tel();c.setSize(500,400);c.setVisible(true);(5)/* * 建立独立事件监听器类del,处理surFace中“删除”点击事件 */import java.awt.*;import java.awt.event.*;import java.sql.*;import javax.swing.*;public class del extends JFrame implements ActionListenerJTextField text1,text2,text3;Container c3;JDialog jd;public del()/删除信息GUI设计 c3=this.getContentPane(); c3.setLayout(new GridLayout(3,1); c3.setFont(new Font(true,Font.TRUETYPE_FONT,13); JPanel p1=new JPanel(); JPanel p4=new JPanel(); / JLabel label=new JLabel(删除教师信息,SwingConstants.CENTER); label.setFont(new Font(TRUE,Font.TRUETYPE_FONT,20); label.setForeground(Color.black); c3.add(label); / JLabel label1=new JLabel(请输入教师工号); text1=new JTextField(10); p1.add(label1); p1.add(text1); c3.add(p1); / JButton b1=new JButton(确定); JButton b2=new JButton(清除); JButton b3=new JButton(退出); p4.add(b1); p4.add(b2); p4.add(b3); c3.add(p4); / this.setSize(500,400); this.setTitle(删除教师信息); /内部匿名类实现“确定”按钮事件 b1.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) Connection con; Statement st; String str1; String s1=text1.getText(); int i=0; try /加载驱动,连接数据源forStu Class.forName(sun.jdbc.odbc.JdbcOdbcDriver); con=DriverManager.getConnection(jdbc:odbc:forStu,); st=con.createStatement(); str1=delete from data1 where 工号=+s1+; i=st.executeUpdate(str1); con.close(); /建立对话框,提示信息 jd=new JDialog(); jd.setLayout(new GridLayout(2,1); JPanel p1=new JPanel(); JPanel p2=new JPanel(); JLabel jl=new JLabel(您成功删除了+i+条记录); JLabel jl2=new JLabel(信息不存在,或已被删除,请重新输入!); JButton b=new JButton(确定); if(i!=1) p1.add(jl2); else p1.add(jl); p2.add(b); jd.add(p1); jd.add(p2); b.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) jd.setVisible(false); ); jd.setSize(255,100); jd.setVisible(true); catch(ClassNotFoundException e1) catch (SQLException e1) ); /“清除”按钮 b2.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) text1.setText(); ); b3.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) del.this.setVisible(false); del.this.dispose(); );/del的方法,实现删除信息的界面public void actionPerformed(ActionEvent e)del d=new del();d.setVisible(true); (6)/* * 建立独立事件监听器类ext,处理surFace中“退出”点击事件 */import java.awt.event.*;public class ext implements ActionListenerpublic void actionPerformed(ActionEvent e)System.exit(0);(7)/* * 建立独立事件监听器类fin,处理surFace中“查询”点击事件 */import java.awt.*;import java.awt.event.*;import java.sql.*;import javax.swing.*;public class fin extends JFrame implements ActionListenerJTextField t1;JButton b1,b2,b3;static Container c1;JDialog jd;public fin()c1=this.getContentPane();setBackground(new Color(215, 215, 215);c1.setLayout(new GridLayout(3,2);JPanel pp = new JPanel();JLabel label0=new JLabel(请您输入要查询的教师工号);label0.setForeground(Color.black);label0.setFont(new Font(TRUE,Font.TRUETYPE_FONT,20);pp.add(label0);c1.add(pp);JPanel p1 = new JPanel();t1=new JTextField(10);p1.add(new Label();p1.add(t1);c1.add(p1);JPanel p2 = new JPanel();b1 = new JButton(确定);b2 = new JButton(清空);b3 = new JButton(退出);p2.add(b1);p2.add(b2);p2.add(b3);c1.add(p2);this.setTitle(查找教师信息);this.setSize(500,400);this.addWindowL
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 中级财务会计(河南财经政法大学)知到智慧树答案
- 死因监测培训试题及答案
- 2025大连安居客平台全程监管下的二手房买卖合同
- 2025年度绿色金融垫资撤押贷款合同及碳排放权抵押担保协议
- 2025版蔬菜种植与农产品电商平台合作合同
- 2025年新型农业灌溉系统安装与运营管理合同
- 2025年水利工程桩基施工与生态修复合同
- 2025版跨境电商合作万能合同范本
- 数据驱动的实时监控与异常检测-洞察及研究
- 2025二手公寓房买卖及贷款担保与房屋租赁服务合同
- 2025年学历类自考专业(学前教育)学前儿童发展-学前教育原理参考题库含答案解析(5套)
- 日本设备销售合同范本
- 2025年芜湖市鸠江区医院招聘16名工作人员笔试参考题库附答案解析
- T-CBDA 86-2025 建筑幕墙、采光顶及金属屋面工程质量验收标准
- 厨房消防安全培训
- 小陈 税务风险应对常见指标与答复思路
- 2025年《中华人民共和国档案法》知识培训试题及答案
- 2025至2030年中国建筑膜行业市场调查研究及发展趋势预测报告
- 变电站新员工培训课件
- 《海上风电场工程测量规程》(NB-T 10104-2018)
- 2021年成都中医药大学辅导员招聘笔试试题及答案解析
评论
0/150
提交评论