Java学生信息管理系统Swing窗体Word格式.docx

上传人:b****1 文档编号:3730376 上传时间:2023-05-02 格式:DOCX 页数:46 大小:167.91KB
下载 相关 举报
Java学生信息管理系统Swing窗体Word格式.docx_第1页
第1页 / 共46页
Java学生信息管理系统Swing窗体Word格式.docx_第2页
第2页 / 共46页
Java学生信息管理系统Swing窗体Word格式.docx_第3页
第3页 / 共46页
Java学生信息管理系统Swing窗体Word格式.docx_第4页
第4页 / 共46页
Java学生信息管理系统Swing窗体Word格式.docx_第5页
第5页 / 共46页
Java学生信息管理系统Swing窗体Word格式.docx_第6页
第6页 / 共46页
Java学生信息管理系统Swing窗体Word格式.docx_第7页
第7页 / 共46页
Java学生信息管理系统Swing窗体Word格式.docx_第8页
第8页 / 共46页
Java学生信息管理系统Swing窗体Word格式.docx_第9页
第9页 / 共46页
Java学生信息管理系统Swing窗体Word格式.docx_第10页
第10页 / 共46页
Java学生信息管理系统Swing窗体Word格式.docx_第11页
第11页 / 共46页
Java学生信息管理系统Swing窗体Word格式.docx_第12页
第12页 / 共46页
Java学生信息管理系统Swing窗体Word格式.docx_第13页
第13页 / 共46页
Java学生信息管理系统Swing窗体Word格式.docx_第14页
第14页 / 共46页
Java学生信息管理系统Swing窗体Word格式.docx_第15页
第15页 / 共46页
Java学生信息管理系统Swing窗体Word格式.docx_第16页
第16页 / 共46页
Java学生信息管理系统Swing窗体Word格式.docx_第17页
第17页 / 共46页
Java学生信息管理系统Swing窗体Word格式.docx_第18页
第18页 / 共46页
Java学生信息管理系统Swing窗体Word格式.docx_第19页
第19页 / 共46页
Java学生信息管理系统Swing窗体Word格式.docx_第20页
第20页 / 共46页
亲,该文档总共46页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

Java学生信息管理系统Swing窗体Word格式.docx

《Java学生信息管理系统Swing窗体Word格式.docx》由会员分享,可在线阅读,更多相关《Java学生信息管理系统Swing窗体Word格式.docx(46页珍藏版)》请在冰点文库上搜索。

Java学生信息管理系统Swing窗体Word格式.docx

可以按照id删除学生的信息,然后显示找到该人。

若查无此人,显示相应的错误信息。

1.3(控制台方式)完善应用程序,实现相应的功能如下:

添加学生信息、修改指定学号的学生信息、显示所有学生信息、按学号查找、按姓名查找、按学号删除、按成绩排序和退出。

1.4(Swing窗体方式)完善应用程序,实现相应的功能如下:

(2)处理思路及关键技术说明

 

(3)程序完整源码(要求格式规范,适当注释)

(4)运行结果截图(按每个操作分别截图)

分三个模块:

一是jdbc的代码,另一个是Swing和AWT的代码,剩下是Student类。

Jdbc一共有两个类:

DBUtil(连接工具类)和Sql类(处理jdbc功能的静态方法)

Swing和AWT一个有两个类:

MyJFrame构建总窗口,MyJPanel对窗口内的面板行修饰。

然后就是Student类和Main主方法类。

关键部分:

1)在主窗体中add三个Jpanel,底层和第二层左右三个,右边的Jpanel实现cardLayout布局,左边的Jpanel添加按钮并添加ActionListener来实现对象的card切换达到不同按钮进入不同功能面板的目的。

2)在MyJPanel类中,所有的init方法均传递参数JPanelp,对传递过来的Panel进行加工修饰,并且调用Sql里面对应功能的方法。

3)Sql中的显示全部信息的方法中使用了ArrayList来存储从studenttbl中读取的对象信息,存储之后为了按照String的方式显示在JtextArea中,又用了listToString方法,通过for循环并追加回车,使每个对象都转化为String并在后面加上了回车(separator),

4)在Sql中的查找,删除,添加都使用了jdbc中的预处理PreparedStatement

在操作完毕后执行sts.executeUpdate();

5)在Sql排序方法中,把所有的信息都存储到list中以后,调用工具类Collections.sort:

根据指定比较器产生的顺序对指定列表进行排序。

classDBUtil

packagetest;

importjava.sql.Connection;

importjava.sql.DriverManager;

importjava.sql.SQLException;

publicclassDBUtil{

privatestaticStringdriver;

privatestaticStringurl;

privatestaticStringusername;

privatestaticStringpassword;

static{

driver="

com.mysql.jdbc.Driver"

;

url="

jdbc:

mysql:

//localhost:

3306/mydb"

username="

root"

password="

123456"

}

publicstaticConnectionopen(){

try{

Class.forName(driver);

returnDriverManager.getConnection(url,username,password);

}catch(Exceptione){

e.printStackTrace();

}

returnnull;

publicstaticvoidclose(Connectionconn){

if(conn!

=null){

try{

conn.close();

}catch(SQLExceptione){

e.printStackTrace();

}

}

classSql

importjava.sql.PreparedStatement;

importjava.sql.ResultSet;

importjava.sql.Statement;

importjava.util.ArrayList;

importjava.util.Collections;

importjava.util.Comparator;

importjava.util.List;

importjavax.swing.JLabel;

importjavax.swing.JOptionPane;

importjavax.swing.JTextArea;

publicclassSql{

publicstaticStringlistToString(List<

Student>

list,charseparator){//使list返回String类型并加入控制符(换行)

StringBuildersb=newStringBuilder();

for(inti=0;

i<

list.size();

i++){

sb.append(list.get(i)).append(separator);

}

returnsb.toString().substring(0,sb.toString().length()-1);

publicstaticList<

disAll(){//打印显示所有信息

//查询

Connectionconn=DBUtil.open();

Stringsql="

selectid,name,frctionJava,fractionMath,fractionOSfromstudentTbl"

Statementstmt;

stmt=conn.createStatement();

ResultSetrs=stmt.executeQuery(sql);

List<

list=newArrayList<

();

//遍历操作

while(rs.next()){

intid=rs.getInt

(1);

Stringname=rs.getString

(2);

doublea=rs.getDouble(3);

doubleb=rs.getDouble(4);

doublec=rs.getDouble(5);

Studentu=newStudent();

u.setId(id);

u.setName(name);

u.setFractionJava(a);

u.setFractionMath(b);

u.setFractionOS(c);

list.add(u);

}

conn.close();

returnlist;

}catch(SQLExceptione){

publicstaticvoidFindByID(longid,JLabellblNewLabel){//按ID查找

ResultSetrs=null;

Stringsql="

select*fromStudentTblwhereid=?

"

PreparedStatementsts=conn.prepareStatement(sql);

sts.setLong(1,id);

rs=sts.executeQuery();

inti=rs.getInt

(1);

lblNewLabel.setText("

|"

+i+"

+name+"

+a+"

+b+"

+c);

}catch(Exceptione){

}finally{

if(rs.first()!

=true)

lblNewLabel.setText("

~~~~~~~查无此人!

~~~~~~~~"

);

publicstaticvoidFindByName(Strings,JLabellblNewLabel){//按Name查找

select*fromStudentTblwherename=?

sts.setString(1,s);

while(rs.next())

{

+id+"

try{

}catch(SQLExceptione)

{

publicstaticvoidDeleteByID(longid){//删除

PreparedStatementsts=null;

inta=0;

sts=conn.prepareStatement("

deletefromStudentTblwhereid=?

a=sts.executeUpdate();

if(a>

0)

JOptionPane.showMessageDialog(null,"

删除成功!

"

WO"

JOptionPane.INFORMATION_MESSAGE);

if(a==0)

无此人!

}catch(Exceptione){

DBUtil.close(conn);

publicstaticvoidSort(JTextAreata,intindex){//排序

//查询

Connectionconn=DBUtil.open();

Statementstmt;

stmt=conn.createStatement();

ResultSetrs=stmt.executeQuery(sql);

List<

//遍历操作

while(rs.next()){

intid=rs.getInt

(1);

Stringname=rs.getString

(2);

doublea=rs.getDouble(3);

doubleb=rs.getDouble(4);

doublec=rs.getDouble(5);

Studentu=newStudent();

u.setId(id);

u.setName(name);

u.setFractionJava(a);

u.setFractionMath(b);

u.setFractionOS(c);

list.add(u);

}

Collections.sort(list,newComparator<

()

{

publicintcompare(Studento1,Studento2)

{

inti=1;

if(index==1)

{i=(int)(o2.getFractionJava()-o1.getFractionJava());

if(index==2){

i=(int)(o2.getFractionMath()-o1.getFractionMath());

}

if(index==3){

i=(int)(o2.getFractionOS()-o1.getFractionOS());

returni;

}

});

Strings=listToString(list,'

\n'

ta.setText(s);

}

publicstaticvoidadd(Studentstu){//添加

PreparedStatementsts;

sts=conn.prepareStatement("

insertintoStudentTblvalues(?

?

)"

sts.setLong(1,stu.getId());

sts.setString(2,stu.getName());

sts.setDouble(3,stu.getFractionJava());

sts.setDouble(4,stu.getFractionMath());

sts.setDouble(5,stu.getFractionOS());

sts.executeUpdate();

}

DBUtil.close(conn);

publicstaticvoidUpdateStudent(Studentstu){//更新

Connectionconn=DBUtil.open();

updatestudenttblsetname='

+stu.getName()+"

'

FrctionJava='

+stu.getFractionJava()+"

FractionMath='

+stu.getFractionMath()+"

FractionOS='

+stu.getFractionOS()+"

whereid='

+stu.getId()+"

}catch(Exceptione){

}

classStudent

importjava.io.Serializable;

publicclassStudentimplementsSerializable{

privatestaticfinallongserialVersionUID=4558876142427402513L;

privateStringname;

privatelongid;

privatedoublefractionOS;

privatedoublefractionJava;

privatedoublefractionMath;

publicStringgetName(){

returnname;

publicvoidsetName(Stringname){

this.name=name;

publiclonggetId(){

returnid;

publicvoidsetId(longid){

this.id=id;

publicdoublegetFractionOS(){

returnfractionOS;

publicvoidsetFractionOS(doublefractionOS){

this.fractionOS=fractionOS;

publicdoublegetFractionJava(){

returnfractionJava;

publicvoidsetFractionJava(doublefractionJava){

this.fractionJava=fractionJava;

publicdoublegetFractionMath(){

returnfractionMath;

publicvoidsetFractionMath(doublefractionMath){

this.fractionMath=fractionMath;

publicStringtoString(){

return(name+"

"

Java:

+fractionJava+

"

Math:

+fractionMath+"

OS:

+fractionOS);

classMyJFrame

importjavax.swing.JFrame;

importjavax.swing.JPanel;

importjava.awt.BorderLayout;

importjava.awt.CardLayout;

importjava.awt.Insets;

importjava.awt.event.ActionEvent;

importjava.awt.event.ActionListener;

importjavax.swing.JButton;

importjava.awt.Color;

importjavax.swing.SwingConstants;

importjava.awt.Font;

publicclassMyJFram

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

当前位置:首页 > 解决方案 > 其它

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2