学生管理系统韩顺平java文档格式.docx

上传人:b****6 文档编号:21590327 上传时间:2023-01-31 格式:DOCX 页数:16 大小:18.38KB
下载 相关 举报
学生管理系统韩顺平java文档格式.docx_第1页
第1页 / 共16页
学生管理系统韩顺平java文档格式.docx_第2页
第2页 / 共16页
学生管理系统韩顺平java文档格式.docx_第3页
第3页 / 共16页
学生管理系统韩顺平java文档格式.docx_第4页
第4页 / 共16页
学生管理系统韩顺平java文档格式.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

学生管理系统韩顺平java文档格式.docx

《学生管理系统韩顺平java文档格式.docx》由会员分享,可在线阅读,更多相关《学生管理系统韩顺平java文档格式.docx(16页珍藏版)》请在冰豆网上搜索。

学生管理系统韩顺平java文档格式.docx

publicStuManageSystemVersion1(){

//创建组件

//Top组件

top=newJPanel();

name=newJLabel("

请输入姓名"

);

jtf=newJTextField(22);

search=newJButton("

查询"

search.addActionListener(this);

top.add(name);

top.add(jtf);

top.add(search);

sm=newStuModel();

sm.queryStu("

select*fromstus"

null);

jt=newJTable(sm);

jt.setSelectionBackground(Color.RED);

jsp=newJScrollPane(jt);

//底部组件

bottom=newJPanel();

add=newJButton("

增加"

add.addActionListener(this);

delete=newJButton("

删除"

delete.addActionListener(this);

update=newJButton("

修改"

update.addActionListener(this);

bottom.add(add);

bottom.add(delete);

bottom.add(update);

//添加组件

this.add(top,BorderLayout.NORTH);

this.add(jsp,BorderLayout.CENTER);

this.add(bottom,BorderLayout.SOUTH);

//设置窗体属性

this.setSize(400,300);

this.setTitle("

学生管理系统"

intw=Toolkit.getDefaultToolkit().getScreenSize().width;

inth=Toolkit.getDefaultToolkit().getScreenSize().height;

this.setLocation(w/2-200,h/2-150);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setVisible(true);

}

publicstaticvoidmain(String[]args){

//TODOAuto-generatedmethodstub

newStuManageSystemVersion1();

//更新数据模型

publicvoidupdStuModel(){

jt.setModel(sm);

@Override

publicvoidactionPerformed(ActionEvente){

if(e.getSource()==search){

Strings=jtf.getText().trim();

Stringname[]={s};

Stringsql="

"

;

if(s.length()!

=0){

sql="

select*fromStuswhereStuName=?

}elseif(s.length()==0){

select*fromStus"

name=null;

}

sm=newStuModel();

sm.queryStu(sql,name);

jt.setModel(sm);

jtf.setText("

}

elseif(e.getSource()==add){

Booleanflag=true;

while(flag){

AddNewStuans=newAddNewStu(this,"

添加新学生"

true);

//更新数据模型

this.updStuModel();

//确认是否添加新的学生

inti=JOptionPane.showConfirmDialog(this,"

是否继续添加学生?

"

JOptionPane.YES_NO_OPTION);

if(i==JOptionPane.NO_OPTION){

flag=false;

}

elseif(e.getSource()==delete){

if(jt.getSelectedRow()==-1){

JOptionPane.showMessageDialog(this,"

请先选择一行数据"

return;

}else{

intselectID=jt.getSelectedRow();

StringstuID[]={jt.getValueAt(selectID,0).toString()};

Stringsql="

deletefromstuswherestuID=?

sm=newStuModel();

sm.updStu(sql,stuID);

elseif(e.getSource()==update){

intid=jt.getSelectedRow();

sm.queryStu("

UpdateStuus=newUpdateStu(this,"

修改学生信息"

true,sm,id);

}

*这是我的一个Stu表的模型

importjava.sql.Connection;

importjava.sql.DriverManager;

importjava.sql.ResultSet;

importjava.sql.SQLException;

importjava.util.Vector;

importjavax.swing.table.AbstractTableModel;

importcom.mysql.fabric.xmlrpc.base.Array;

publicclassStuModelextendsAbstractTableModel{

ResultSetrs;

Vector<

String>

cloumn;

Vector>

row;

SqlHelpersh;

//查询数据

publicvoidqueryStu(Stringsql,String[]args){

//中间的显示组件

cloumn=newVector<

();

cloumn.add("

学生ID"

姓名"

年龄"

性别"

系别"

row=newVector<

sh=newSqlHelper();

rs=sh.query(sql,args);

try{

while(rs.next()){

Vector<

Object>

hang=newVector<

hang.add(rs.getInt

(1));

hang.add(rs.getString

(2));

hang.add(rs.getInt(3));

hang.add(rs.getString(4));

hang.add(rs.getString(5));

row.add(hang);

}catch(Exceptione){

//TODO:

handleexception

sh.close();

//增.删.改操作

publicbooleanupdStu(Stringsql,String[]args){

returnsh.updSQL(sql,args);

//得到共有多少列

publicintgetColumnCount(){

returnthis.cloumn.size();

//得到共有多少行

publicintgetRowCount(){

returnthis.row.size();

//得到某行某列的值

publicObjectgetValueAt(introwIndex,intcolumnIndex){

returnthis.row.get(rowIndex).get(columnIndex);

publicStringgetColumnName(intindex){

returnthis.cloumn.get(index);

importjava.awt.BorderLayout;

importjava.awt.GridLayout;

publicclassAddNewStuextendsJDialogimplementsActionListener{

//定义swing组件

JPaneltop,bottom,left;

JLabelstuID,stuName,stuAge,stuSex,stuDepart;

JTextFieldid,name,age,sex,depart;

JButtonsave,cancel;

StuModelsm=null;

//构造函数

publicAddNewStu(JFrameowner,Stringtitle,booleanmodal){

super(owner,title,modal);

//创建组件

top=newJPanel(newGridLayout(5,1));

left=newJPanel(newGridLayout(5,1));

stuID=newJLabel("

JLabel.CENTER);

stuName=newJLabel("

stuAge=newJLabel("

stuSex=newJLabel("

stuDepart=newJLabel("

id=newJTextField(15);

name=newJTextField(15);

age=newJTextField(15);

sex=newJTextField(15);

depart=newJTextField(15);

top.add(stuID);

top.add(stuName);

top.add(stuAge);

top.add(stuSex);

top.add(stuDepart);

left.add(id);

left.add(name);

left.add(age);

left.add(sex);

left.add(depart);

bottom=newJPanel();

save=newJButton("

保存"

save.addActionListener(this);

cancel=newJButton("

取消"

cancel.addActionListener(this);

bottom.add(save);

bottom.add(cancel);

this.add(top,BorderLayout.CENTER);

this.add(left,BorderLayout.EAST);

this.add(bottom,BorderLayout.SOUTH);

//设置窗体属性

this.setSize(230,200);

this.setLocation(1000,300);

if(e.getSource()==save){

Stringvalues[]={id.getText().trim(),name.getText().trim(),

age.getText().trim(),sex.getText().trim(),

depart.getText().trim()};

Stringsql="

insertintostusvalues(?

?

)"

sm=newStuModel();

sm.updStu(sql,values);

this.dispose();

elseif(e.getSource()==cancel){

importjavax.swing.JButton;

importjavax.swing.JDialog;

importjavax.swing.JFrame;

importjavax.swing.JLabel;

importjavax.swing.JPanel;

importjavax.swing.JTextField;

publicclassUpdateStuextendsJDialogimplementsActionListener{

Stringvalues[];

publicUpdateStu(JFrameowner,Stringtitle,booleanmodal,StuModelsm,

intidValue){

id.setText(sm.getValueAt(idValue,0).toString());

id.setEditable(false);

name.setText(sm.getValueAt(idValue,1).toString());

age.setText(sm.getValueAt(idValue,2).toString());

sex.setText(sm.getValueAt(idValue,3).toString());

depart.setText(sm.getValueAt(idValue,4).toString());

Stringvalues[]={name.getText().trim(),age.getText().trim(),

sex.getText().trim(),depart.getText().trim(),

id.getTex

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

当前位置:首页 > 教学研究 > 教学案例设计

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

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