Java网络编程实践课程设计.docx

上传人:b****7 文档编号:26574464 上传时间:2023-06-20 格式:DOCX 页数:40 大小:823.80KB
下载 相关 举报
Java网络编程实践课程设计.docx_第1页
第1页 / 共40页
Java网络编程实践课程设计.docx_第2页
第2页 / 共40页
Java网络编程实践课程设计.docx_第3页
第3页 / 共40页
Java网络编程实践课程设计.docx_第4页
第4页 / 共40页
Java网络编程实践课程设计.docx_第5页
第5页 / 共40页
点击查看更多>>
下载资源
资源描述

Java网络编程实践课程设计.docx

《Java网络编程实践课程设计.docx》由会员分享,可在线阅读,更多相关《Java网络编程实践课程设计.docx(40页珍藏版)》请在冰豆网上搜索。

Java网络编程实践课程设计.docx

Java网络编程实践课程设计

Java网络编程实践

课程设计说明书

课程名称:

Java网络编程课程设计

题目:

基于C/S的学生信息管理

姓名:

学号:

教学班号:

指导教师:

王小刚

 

兰州交通大学软件科学与工程系

 

二○13年12月27日

 

任务书

实现应用,可以通过网络在客户端对存放在服务器端的学生信息表(至少包含学号、姓名、性别、年龄、籍贯等字段)学生纪录增、删、改、查,并返回结果。

要能通过菜单选择功能。

基于Socket,多客户端使用多线程,以能同时从多个客户端执行功能。

必须提供友好直观、布局合理的图形界面选择功能、显示信息和填写修改信息。

成员及分工列表

图形界面设计者:

数据库设计者:

Socket设计者:

多线程设计者:

项目简述和目的

熟悉JAVA语法,掌握图形化界面、多线程、网络、数据库等综合编程,掌握用编程语言开发由若干功能组成的小型项目的基本流程,增强动手实践能力,巩固和加强书本知识的学习,体会JAVA编程的特点。

解题基本思路

设计的信息管理系统中的窗体部分,没有使用菜单,而是按钮。

菜单虽然简单,方便,但我认为在窗体里运用按钮是有必要的,这样可以方便添加、删除,修改等动作,通过一步步地做,慢慢的集合,比较的清晰,还显得比较的有层次感.利用Swing设计图形界面利用Access表设计数据库,利用socket设计网络信息管理模块

分析和设计

学生管理系统要实现查询,添加,删除,显示,修改等功能。

查询不存在要报错,添加相同也要报错,删除不存在的号也要报错,修改不成功也要报错。

如果成功的话也要提示。

而且每一步都要密码才能进行操作,否则报错提醒!

主要程序源代码

Client源代码

packagesocket;

importjava.io.*;

import.*;

importjava.awt.*;

importjavax.swing.*;

importjava.awt.event.*;

classClientextendsJFrameimplementsActionListener//登入界面功能是输入正确的账号和密码才能进入,错误的

话返回错误提示!

{

privateJLabelusernameLabel;//帐号

privateJLabela;//标题

privateJTextFieldusernameTextField;//帐号文本框

privateJLabelpasswordLabel;//密码

privateJPasswordFieldpasswordField;//密码文本框

privateJButtonbutton1;//确定按钮

privateJButtonbutton2;//取消按钮

publicClient()

{

super.setTitle("登录界面");

Containerc=getContentPane();

c.setLayout(null);

a=newJLabel("欢迎进入学生登入系统!

");

a.setBounds(50,30,300,30);

a.setFont(newFont("黑色",Font.BOLD,25));

usernameLabel=newJLabel("账号");

usernameLabel.setBounds(50,90,170,30);

usernameLabel.setFont(newFont("黑色",Font.BOLD,30));

usernameTextField=newJTextField();

usernameTextField.setBounds(150,90,170,30);

usernameTextField.setFont(newFont("宋体",Font.BOLD,20));

passwordLabel=newJLabel("密码:

");

passwordLabel.setBounds(50,120,170,30);

passwordLabel.setFont(newFont("黑色",Font.BOLD,30));

passwordField=newJPasswordField();

passwordField.setBounds(150,120,170,30);

passwordField.setFont(newFont("黑色",Font.BOLD,30));

passwordField.setEchoChar('*');

button1=newJButton();

button1.setText("进入");

button1.setFont(newFont("黑色",Font.BOLD,20));

button1.setBounds(50,160,100,30);

button2=newJButton();

button2.setText("退出");

button2.setFont(newFont("黑色",Font.BOLD,20));

button2.setBounds(220,160,100,30);

button1.addActionListener(this);//按钮监听

button2.addActionListener(

newActionListener()

{

publicvoidactionPerformed(ActionEvente)

{

System.exit(0);

}

}

);

c.add(passwordLabel);

c.add(passwordField);

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);

}

privatevoidshowText()//登入失败消息框

{

Stringxie;

xie=usernameTextField.getText();

JOptionPane.showMessageDialog(this.getParent(),"登入失败!

"+xie);

}

privatevoidshowText1()//登入成功消息框

{

Stringxie;

xie=usernameTextField.getText();

JOptionPane.showMessageDialog(this.getParent(),"登入成功!

"+xie);

}

publicvoidactionPerformed(ActionEvente)//按钮监听事件

{

Socketssocket=null;

Stringst1,st2,st3;

finalPrintWriterwriter1;

st1=usernameTextField.getText();

st2=passwordField.getText();

st3="进入"+","+st1+","+st2;//把帐号和密码打包成字符串

try

{

ssocket=newSocket("localHost",10000);//创建socket

writer1=newPrintWriter(ssocket.getOutputStream());//发送给服务器!

if(!

(st1.equals(null))&&!

(st2.equals(null)))//判断是否为空

{

writer1.println(st3);

writer1.flush();

}

elseif(st1.equals(null)||st2.equals(null))//判断是否为空

{

writer1.println("error1");

writer1.flush();

}

BufferedReaderread=newBufferedReader(newInputStreamReader

(ssocket.getInputStream()));

Strings_red=null;

System.out.println("pleasewait.......");

while(true)

{

s_red=read.readLine();

if(s_red!

=null)

break;

}

if(s_red.equals("yes"))//读取服务端的内容,如果是yes执行Client1的类

{

showText1();

dispose();

newClient1();

}

else//读取服务端的内容,如果不是yes执行showText()报错提醒!

{

showText();

usernameTextField.setText(null);

passwordField.setText(null);

}

}

catch(Exceptione1)

{

e1.printStackTrace();

}

}

publicstaticvoidmain(String[]args)throwsIOException

{

Clients=newClient();

}

}

classClient1extendsJFrame//登录界面的类包含查询,删除,增添,修改,返回等按钮!

共4个按钮监听对象!

{

privateJButtonbutton1,button2,button3,button4,button5,button6;

publicClient1()

{

super.setTitle("登录界面");

Containerc=getContentPane();

setLayout(null);

button1=newJButton();

button1.setText("查询");

button1.setFont(newFont("黑色",Font.BOLD,20));

button1.setBounds(50,50,120,50);

button2=newJButton();

button2.setText("删除");

button2.setFont(newFont("黑色",Font.BOLD,20));

button2.setBounds(220,50,120,50);

button3=newJButton();

button3.setText("增添");

button3.setFont(newFont("黑色",Font.BOLD,20));

button3.setBounds(50,150,120,50);

button4=newJButton();

button4.setText("修改");

button4.setFont(newFont("黑色",Font.BOLD,20));

button4.setBounds(220,150,120,50);

button5=newJButton();

button5.setText("显示");

button5.setFont(newFont("黑色",Font.BOLD,20));

button5.setBounds(50,250,120,50);

button6=newJButton();

button6.setText("返回");

button6.setFont(newFont("黑色",Font.BOLD,20));

button6.setBounds(220,250,120,50);

button1.addActionListener(

newActionListener()

{

publicvoidactionPerformed(ActionEvente)

{

dispose();

newClient2();

}

}

);

button2.addActionListener(

newActionListener()

{

publicvoidactionPerformed(ActionEvente)

{

dispose();

newClient4();

}

}

);

button3.addActionListener(

newActionListener()

{

publicvoidactionPerformed(ActionEvente)

{

dispose();

newClient3();

}

}

);

button4.addActionListener(

newActionListener()

{

publicvoidactionPerformed(ActionEvente)

{

dispose();

newClient5();

}

}

);

button5.addActionListener(

newActionListener()

{

publicvoidactionPerformed(ActionEvente)

{

dispose();

newClient6();

}

}

);

button6.addActionListener(

newActionListener()

{

publicvoidactionPerformed(ActionEvente)

{

dispose();

newClient();

}

}

);

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);

setVisible(true);

}

publicstaticvoidmain(String[]args)//throwsIOException

{

newClient1();

}

}

classClient2extendsJFrameimplementsActionListener//查询类的功能是输入学号和密码,如果正确则返回成功

的提醒,如果失败则返回失败的提醒,如果该学好存在,则返回存在的提醒!

{

privateJLabelusernameLabel1;

privateJLabelusernameLabel2;

privateJLabelusernameLabel3;

privateJLabelusernameLabel4;

privateJLabelusernameLabel5;

privateJLabelusernameLabel6;

privateJLabelusernameLabel7;

privateJLabelusernameLabel8;

privateJTextFieldusernameTextField1;

privateJTextFieldusernameTextField2;

privateJTextFieldusernameTextField3;

privateJTextFieldusernameTextField4;

privateJTextFieldusernameTextField5;

privateJTextFieldusernameTextField6;

privateJTextFieldusernameTextField7;

privateJTextFieldusernameTextField8;

privateJButtonbutton1;

privateJButtonbutton2;

privateJLabellabel1;

publicClient2()

{

super.setTitle("学生操作界面");

Containerc=getContentPane();

c.setLayout(null);

label1=newJLabel("欢迎进入学生查询系统!

");

label1.setBounds(40,20,400,30);

label1.setFont(newFont("黑色",Font.BOLD,35));

usernameLabel1=newJLabel("查询号");

usernameLabel1.setBounds(70,110,200,30);

usernameLabel1.setFont(newFont("黑色",Font.BOLD,30));

usernameTextField1=newJTextField();

usernameTextField1.setBounds(170,110,200,30);

usernameTextField1.setFont(newFont("宋体",Font.BOLD,30));

usernameLabel2=newJLabel("密码:

");

usernameLabel2.setBounds(70,150,200,30);

usernameLabel2.setFont(newFont("黑色",Font.BOLD,32));

usernameTextField2=newJTextField();

usernameTextField2.setBounds(170,150,200,30);

usernameTextField2.setFont(newFont("黑色",Font.BOLD,30));

usernameLabel3=newJLabel("性别:

");

usernameLabel3.setFont(newFont("黑色",Font.BOLD,32));

usernameLabel3.setBounds(70,190,200,30);

usernameTextField3=newJTextField();

usernameTextField3.setBounds(170,190,200,30);

usernameTextField3.setFont(newFont("黑色",Font.BOLD,30));

usernameLabel4=newJLabel("籍贯:

");

usernameLabel4.setBounds(70,230,200,30);

usernameLabel4.setFont(newFont("黑色",Font.BOLD,30));

usernameTextField4=newJTextField();

usernameTextField4.setBounds(170,230,200,30);

usernameTextField4.setFont(newFont("黑色",Font.BOLD,30));

usernameLabel5=newJLabel("专业:

");

usernameLabel5.setBounds(70,270,200,30);

usernameLabel5.setFont(newFont("黑色",Font.BOLD,30));

usernameTextField5=newJTextField();

usernameTextField5.setBounds(170,270,200,30);

usernameTextField5.setFont(newFont("黑色",Font.BOLD,30));

usernameLabel6=newJLabel("姓名:

");

usernameLabel6.setBounds(70,310,200,30);

usernameLabel6.setFont(newFont("黑色",Font.BOLD,30));

usernameTextField6=newJTextField();

usernameTextField6.setBounds(170,310,200,30);

usernameTextField6.setFont(newFont("黑色",Font.BOLD

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 法律文书 > 判决书

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1