



版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、精品文档J av a 网 络 编 程 实 践课程设计说明书课程名称: Java 网络编程课程设计题目:基于 C/S 的学生信息管理姓名:学号:教学班号 :指导教师:王 小 刚兰州交通大学软件科学与工程系二13年12月27日。1欢迎下载精品文档。2欢迎下载精品文档任务书实现应用,可以通过网络在客户端对存放在服务器端的学生信息表(至少包含学号、姓名、性别、年龄、籍贯等字段)学生纪录增、删、改、查,并返回结果。要能通过菜单选择功能。基于Socket ,多客户端使用多线程,以能同时从多个客户端执行功能。必须提供友好直观、布局合理的图形界面选择功能、显示信息和填写修改信息。成员及分工列表图形界面设计者:
2、数据库设计者:Socket设计者:多线程设计者:项目简述和目的熟悉 JAVA 语法,掌握图形化界面、多线程、 网络、 数据库等综合编程,掌握用编程语言开发由若干功能组成的小型项目的基本流程,增强动手实践能力,巩固和加强书本知识的学习,体会 JAVA编程的特点。解题基本思路设计的信息管理系统中的窗体部分,没有使用菜单,而是按钮。菜单虽然简单,方便,但我认为在窗体里运用按钮是有必要的,这样可以方便添加、删除,修改等动作,通过一步步地做,慢慢的集合,比较的清晰,还显得比较的有层次感 . 利用 Swing 设计图形界面利用 Access 表设计数据库,利用 socket 设计网络信息管理模块分析和设计
3、。3欢迎下载精品文档学生管理系统要实现查询,添加,删除,显示,修改等功能。查询不存在要报错,添加相同也要报错,删除不存在的号也要报错,修改不成功也要报错。如果成功的话也要提示。而且每一步都要密码才能进行操作,否则报错提醒!主要程序源代码Client源代码package socket;import java.io.*;import .*;import java.awt.*;import javax.swing.*;import java.awt.event.*;class Client extends JFrame implements ActionListener/登入界面功能是输入正确的账号
4、和密码才能进入,错误的话返回错误提示!private JLabel usernameLabel;/帐号private JLabel a;/标题private JTextField usernameTextField;/帐号文本框private JLabel passwordLabel;/密码private JPasswordField passwordField;/密码文本框private JButton button1;/确定按钮private JButton button2;/取消按钮public Client()super.setTitle("登录界面 ");Cont
5、ainer c=getContentPane();c.setLayout(null);a=new JLabel("欢迎进入学生登入系统!");a.setBounds(50,30,300,30);a.setFont(new Font("黑色 ",Font.BOLD,25);usernameLabel=new JLabel("账号 ");usernameLabel.setBounds(50,90,170,30);。4欢迎下载精品文档usernameLabel.setFont(new Font("黑色 ",Font.BO
6、LD,30);usernameTextField=new JTextField();usernameTextField.setBounds(150,90,170,30);usernameTextField.setFont(new Font("宋体 ",Font.BOLD,20);passwordLabel=new JLabel("密码: ");passwordLabel.setBounds(50,120,170,30);passwordLabel.setFont(new Font("黑色 ",Font.BOLD,30);passwor
7、dField=new JPasswordField();passwordField.setBounds(150,120,170,30);passwordField.setFont(new Font("黑色 ",Font.BOLD,30);passwordField.setEchoChar('*');button1=new JButton();button1.setText("进入 ");button1.setFont(new Font("黑色 ",Font.BOLD,20);button1.setBounds(50,1
8、60,100,30);button2=new JButton();button2.setText("退出 ");button2.setFont(new Font("黑色 ",Font.BOLD,20);button2.setBounds(220,160,100,30);button1.addActionListener(this);/按钮监听button2.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)System.exit(0););c.a
9、dd(passwordLabel);c.add(passwordField);。5欢迎下载精品文档c.add(usernameLabel);c.add(button1);c.add(button2);c.add(usernameTextField);c.add(a);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400,300);setLocation(322,30);setVisible(true);private void showText()/登入失败消息框String xie;xie=usernameTextField.
10、getText();JOptionPane.showMessageDialog(this.getParent(),"登入失败!"+xie);private void showText1()/登入成功消息框String xie;xie=usernameTextField.getText();JOptionPane.showMessageDialog(this.getParent(),"登入成功!"+xie);public void actionPerformed(ActionEvent e)/按钮监听事件Socket ssocket = null;Stri
11、ng st1,st2,st3;final PrintWriter writer1;st1=usernameTextField.getText();st2=passwordField.getText();st3="进入 "+","+st1+","+st2;/把帐号和密码打包成字符串tryssocket=new Socket("localHost",10000);/创建 socketwriter1=newPrintWriter(ssocket.getOutputStream();/发送给服务器!。6欢迎下载精品文档if
12、(!(st1.equals(null) && !(st2.equals(null)/判断是否为空writer1.println(st3);writer1.flush();else if(st1.equals(null) | st2.equals(null)/判断是否为空writer1.println("error1");writer1.flush();BufferedReader read=new BufferedReader(new InputStreamReader(ssocket.getInputStream();String s_red=null;S
13、ystem.out.println("please wait.");while(true)s_red=read.readLine();if(s_red!=null)break;if(s_red.equals("yes")/读取服务端的内容,如果是yes执行Client1的类showText1();dispose();new Client1();else/读取服务端的内容,如果不是yes 执行 showText() 报错提醒!showText();usernameTextField.setText(null);passwordField.setText(n
14、ull);catch (Exception e1)。7欢迎下载精品文档e1.printStackTrace();public static void main(String args)throws IOExceptionClient s=new Client();class Client1 extends JFrame /登录界面的类包含查询,删除,增添,修改,返回等按钮!共4 个按钮监听对象!private JButton button1,button2,button3,button4,button5,button6;public Client1()super.setTitle("
15、登录界面 ");Container c=getContentPane();setLayout(null);button1=new JButton();button1.setText("查询 ");button1.setFont(new Font("黑色 ",Font.BOLD,20);button1.setBounds(50,50,120,50);button2=new JButton();button2.setText("删除 ");button2.setFont(new Font("黑色 ",Font
16、.BOLD,20);button2.setBounds(220,50,120,50);button3=new JButton();button3.setText("增添 ");button3.setFont(new Font("黑色 ",Font.BOLD,20);button3.setBounds(50,150,120,50);button4=new JButton();button4.setText("修改 ");button4.setFont(new Font("黑色 ",Font.BOLD,20);butt
17、on4.setBounds(220,150,120,50);button5=new JButton();button5.setText("显示 ");button5.setFont(new Font("黑色 ",Font.BOLD,20);。8欢迎下载精品文档button5.setBounds(50,250,120,50);button6=new JButton();button6.setText("返回 ");button6.setFont(new Font("黑色 ",Font.BOLD,20);button6
18、.setBounds(220,250,120,50);button1.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)dispose();new Client2(););button2.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)dispose();new Client4(););button3.addActionListener(new ActionListener(
19、)public void actionPerformed(ActionEvent e)dispose();new Client3(););button4.addActionListener(new ActionListener()。9欢迎下载精品文档public void actionPerformed(ActionEvent e)dispose();new Client5(););button5.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)dispose();new Clien
20、t6(););button6.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)dispose();new Client(););c.add(button1);c.add(button2);c.add(button3);c.add(button4);c.add(button5);c.add(button6);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setSize(400,450);setLocation(322,30);。10欢迎下
21、载精品文档setVisible(true);public static void main(String args)/throws IOException new Client1();class Client2 extends JFrame implements ActionListener/查询类的功能是输入学号和密码,如果正确则返回成功的提醒,如果失败则返回失败的提醒,如果该学好存在,则返回存在的提醒!private JLabel usernameLabel1;private JLabel usernameLabel2;private JLabel usernameLabel3;priva
22、te JLabel usernameLabel4;private JLabel usernameLabel5;private JLabel usernameLabel6;private JLabel usernameLabel7;private JLabel usernameLabel8;private JTextField usernameTextField1;private JTextField usernameTextField2;private JTextField usernameTextField3;private JTextField usernameTextField4;pri
23、vate JTextField usernameTextField5;private JTextField usernameTextField6;private JTextField usernameTextField7;private JTextField usernameTextField8;private JButton button1;private JButton button2;private JLabel label1;public Client2()super.setTitle("学生操作界面 ");Container c=getContentPane();
24、c.setLayout(null);label1=new JLabel("欢迎进入学生查询系统!");。11欢迎下载精品文档label1.setBounds(40,20,400,30);label1.setFont(new Font("黑色 ",Font.BOLD,35);usernameLabel1=new JLabel("查询号 ");usernameLabel1.setBounds(70,110,200,30);usernameLabel1.setFont(new Font("黑色 ",Font.BOLD,3
25、0);usernameTextField1=new JTextField();usernameTextField1.setBounds(170,110,200,30);usernameTextField1.setFont(new Font("宋体 ",Font.BOLD,30);usernameLabel2=new JLabel("密码: ");usernameLabel2.setBounds(70,150,200,30);usernameLabel2.setFont(new Font("黑色 ",Font.BOLD,32);user
26、nameTextField2=new JTextField();usernameTextField2.setBounds(170,150,200,30);usernameTextField2.setFont(new Font("黑色 ",Font.BOLD,30);usernameLabel3=new JLabel("性别: ");usernameLabel3.setFont(new Font("黑色 ",Font.BOLD,32);usernameLabel3.setBounds(70,190,200,30);usernameTex
27、tField3=new JTextField();usernameTextField3.setBounds(170,190,200,30);usernameTextField3.setFont(new Font("黑色 ",Font.BOLD,30);usernameLabel4=new JLabel("籍贯: ");usernameLabel4.setBounds(70,230,200,30);usernameLabel4.setFont(new Font("黑色 ",Font.BOLD,30);usernameTextField4
28、=new JTextField();usernameTextField4.setBounds(170,230,200,30);usernameTextField4.setFont(new Font("黑色 ",Font.BOLD,30);usernameLabel5=new JLabel("专业: ");usernameLabel5.setBounds(70,270,200,30);usernameLabel5.setFont(new Font("黑色 ",Font.BOLD,30);usernameTextField5=new JT
29、extField();usernameTextField5.setBounds(170,270,200,30);usernameTextField5.setFont(new Font("黑色 ",Font.BOLD,30);usernameLabel6=new JLabel("姓名: ");usernameLabel6.setBounds(70,310,200,30);usernameLabel6.setFont(new Font("黑色 ",Font.BOLD,30);usernameTextField6=new JTextFiel
30、d();。12欢迎下载精品文档usernameTextField6.setBounds(170,310,200,30);usernameTextField6.setFont(new Font("黑色 ",Font.BOLD,30);usernameLabel7=new JLabel("电话: ");usernameLabel7.setBounds(70,350,200,30);usernameLabel7.setFont(new Font("黑色 ",Font.BOLD,30);usernameTextField7=new JText
31、Field();usernameTextField7.setBounds(170,350,200,30);usernameTextField7.setFont(new Font("宋体 ",Font.BOLD,30);usernameLabel8=new JLabel("QQ:");usernameLabel8.setBounds(70,390,200,30);usernameLabel8.setFont(new Font("黑色 ",Font.BOLD,30);usernameTextField8=new JTextField();
32、usernameTextField8.setBounds(170,390,200,30);usernameTextField8.setFont(new Font("宋体 ",Font.BOLD,30);button1=new JButton();button1.setText("查询 ");button1.setFont(new Font("黑色 ",Font.BOLD,30);button1.setBounds(60,470,130,40);button2=new JButton();button2.setText("返回
33、 ");button2.setFont(new Font("黑色 ",Font.BOLD,30);button2.setBounds(270,470,130,40);c.add(usernameLabel1);c.add(usernameLabel2);c.add(usernameLabel3);c.add(usernameLabel4);c.add(usernameLabel5);c.add(usernameLabel6);c.add(usernameLabel7);c.add(usernameLabel8);c.add(button1);c.add(butto
34、n2);。13欢迎下载精品文档c.add(usernameTextField1);c.add(usernameTextField2);c.add(usernameTextField3);c.add(usernameTextField4);c.add(usernameTextField5);c.add(usernameTextField6);c.add(usernameTextField7);c.add(usernameTextField8);c.add(label1);button1.addActionListener(this);button2.addActionListener(new A
35、ctionListener()public void actionPerformed(ActionEvent e)dispose();new Client1(););setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setSize(470,580);setLocation(322,30);setVisible(true);public static void main(String args)Client2 s=new Client2();private void showText()String xie;xie=usernameTextField1
36、.getText();JOptionPane.showMessageDialog(this.getParent(),"查询成功! "+xie);。14欢迎下载精品文档private void showText2()String xie;xie=usernameTextField1.getText();JOptionPane.showMessageDialog(this.getParent(),"该号不存在!"+xie);public void actionPerformed(ActionEvent e)Socket ssocket = null;Stri
37、ng str, st1,st2;final PrintWriter writer1;st1=usernameTextField1.getText();st2=usernameTextField2.getText();str="查询 "+","+st1+","+st2;tryssocket=new Socket("localHost",10000); writer1=new PrintWriter(ssocket.getOutputStream(); if(!(st1.equals(null) &&
38、!(st2.equals(null) writer1.println(str);writer1.flush();else if(st1.equals(null) | st2.equals(null)writer1.println("error1");writer1.flush();BufferedReader read=new BufferedReader(new InputStreamReader(ssocket.getInputStream();String line=null;System.out.println("please wait.");l
39、ine=read.readLine();if(line.equals("Not1")。15欢迎下载精品文档showText2();usernameTextField1.setText(null);usernameTextField2.setText(null);usernameTextField3.setText(null);usernameTextField4.setText(null);usernameTextField5.setText(null);usernameTextField6.setText(null);usernameTextField7.setText(
40、null);usernameTextField8.setText(null);elseString sarry=line.split(","); usernameTextField1.setText(sarry1); usernameTextField2.setText(sarry2); usernameTextField3.setText(sarry3); usernameTextField4.setText(sarry4); usernameTextField5.setText(sarry5); usernameTextField6.setText(sarry6); u
41、sernameTextField7.setText(sarry7); usernameTextField8.setText(sarry8); showText();/catch (Exception e1)e1.printStackTrace();Server 的源代码package socket;import java.io.*;import .*;import java.sql.*;public class Server /Server类通过引用来实现多线程。16欢迎下载精品文档public static void main(String args)Thread1 s=new Thread
42、1();s.start();class Thread1 extends Thread/多线程类static ServerSocket server;static Socket ssocket;static BufferedReader reader1;static BufferedReader reader2;static String sql, databack;static Stringid,password,address,myname,class1,QQ,phone,sex,school; static ResultSet rs; static Statement stmt; stat
43、icConnection conn;public void run()/多线程的run ()方法tryfinal Stringdb_driver="sun.jdbc.odbc.JdbcOdbcDriver" /final String db_url="jdbc:odbc:Driver=连接多线程!Microsoft Access Driver (*.mdb, *.accdb);DBQ=d:/my1.mdb" trycatch(Exception e)e.printStackTrace();。17欢迎下载精品文档tryserver=new ServerSo
44、cket(10000);/建立端口System.out.println("服务器已经创建!等待客户机的链接.");int flag=0;int flag1=0;while(true)ssocket=server.accept();/连接客户端System.out.println("完成链接! ");reader1=new BufferedReader(newInputStreamReader(ssocket.getInputStream();PrintWriter writer2=newPrintWriter(ssocket.getOutputStrea
45、m();String s1=reader1.readLine();String sarry=s1.split(",");sql="select*from one"/连接数据库中的表名Class.forName(db_driver);conn=DriverManager.getConnection(db_url,"","");if(conn!=null)System.out.println("数据库已连接 .");。18欢迎下载精品文档elseSystem.out.println("连接
46、失败! ");stmt=conn.createStatement();rs=stmt.executeQuery(sql);if(sarry0.equals("进入 ")/获取客户端的进入功能while(rs.next()id=rs.getString("ID"); password=rs.getString("password");if(sarry1.equals(id) && sarry2.equals(password)intnumber1=Integer.parseInt(id);intnumber2=
47、Integer.parseInt(password);if(number1=201211016 && number2=16)flag=1;。19欢迎下载精品文档break;if(flag=1)writer2.println("yes");writer2.flush();flag=0;elsewriter2.println("no");writer2.flush();stmt.close();conn.close();else if(sarry0.equals("查询 ")/ 获取客户端的查询功能while(rs.nex
48、t()school=rs.getString("school");。20欢迎下载精品文档id=rs.getString("ID");password=rs.getString("password");sex=rs.getString("sex");address=rs.getString("address");class1=rs.getString("class");myname=rs.getString("myname");phone=rs.getString(
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年山西货运从业资格仿真考题
- 二零二五孤儿收养协议书
- 街道卫生管理制度标准
- 党政办人员管理制度
- 长城宿舍管理制度规定
- 酒店客房房价管理制度
- 餐厅安全作业管理制度
- 骑行特殊设备管理制度
- 集体员工寝室管理制度
- 餐饮工资发放管理制度
- 医疗手术室物品清点课件
- 干眼基础检查、诊断试题
- AQ∕T 3001-2021 加油(气)站油(气)储存罐体阻隔防爆技术要求
- 道路交通肇事逃逸案件查缉预案
- 集中空调通风系统卫生监督要点课件
- 2024年全国高中生物联赛竞赛试题和答案
- 阿里巴巴与四十大盗的故事
- 生产班组计划管理培训课件
- 《制药分离工程》课件
- 浅谈小学音乐教学中的情境创设
- 【公开课】Unit+2Reading+and+Thinking(2019)选择性必修第二册
评论
0/150
提交评论