基于JAVA的学生成绩管理系统源代码

更新时间:2024-04-06 17:55:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

Java程序设计

系 专 业 班 级 学 号 姓 名 题 目 任课教师

电气信息系

软件 1342

131842352

朱家军

学生成绩管理系统

一:要求 1、 2、 3、 4、 5、 6、

用到书上(课本或实验册)上的至少三个实例 用到至少两种布局和至少四种组件 用到对话框

用到对数据库的查询、删除、添加和修改 最好用到输入输出流 具有一定的实际意义

二:内容

本系统用access作为数据库,用到了书上的布局实例和数据库连接实例 功能: 1、输入十个同学的学号,姓名,出生日期,二科成绩(学,大学英语) 。

2、输入学号查询学生信息。 3、删除记录 4、查询记录 5、添加记录 6、修改记录 1.简单的方式(java)

import java.awt.Button; import java.awt.Color;

import java.awt.FlowLayout; import java.awt.Font; import java.awt.Frame; import java.awt.Label; import java.awt.TextField;

import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent;

import javax.swing.JOptionPane;

public class 查询成绩登陆系统 extends Frame{ private Label lab_stuNum,lab_stuPassword;

private TextField tf_stuNum,tf_stuPassword; private Button bt_login,bt_reset; public Label getLab_stuNum() { if(this.lab_stuNum==null){

this.lab_stuNum=new Label(\学号\ }

return lab_stuNum; }

public Label getLab_stuPassword() { if(this.lab_stuPassword==null){

this.lab_stuPassword=new Label(\密码\ }

return lab_stuPassword; }

public TextField getTf_stuNum() { if(this.tf_stuNum==null){

this.tf_stuNum=new TextField(15); }

return tf_stuNum; }

public TextField getTf_stuPassword() { if(this.tf_stuPassword==null){

this.tf_stuPassword=new TextField(15); this.tf_stuPassword.setEchoChar('●'); }

return tf_stuPassword; }

public Button getBt_login() {

if(this.bt_login==null){

this.bt_login=new Button(\登陆\

this.bt_login.addActionListener(new ActionListener(){

@Override

public void actionPerformed(ActionEvent e) { String account=tf_stuNum.getText(); if(account==null||\

JOptionPane.showMessageDialog(查询成绩登陆系统.this, \请输入学号\

tf_stuNum.requestFocus(); }

String pw=tf_stuPassword.getText(); if(pw==null||\

JOptionPane.showMessageDialog(查询成绩登陆系统.this, \请输入密码\

tf_stuPassword.requestFocus(); }

String db_account=\ String db_password=\

if(account.equals(db_account)&&pw.equals(db_password)){

JOptionPane.showMessageDialog(查询成绩登陆系统.this, \登陆成功\

查询成绩登陆系统.this.dispose(); }else{

JOptionPane.showMessageDialog(查询成绩登陆系统.this,\账号密码不对\

tf_stuNum.setText(\

tf_stuPassword.setText(\ tf_stuNum.requestFocus(); } }

2.C语言

#include

#include #include #include struct student //结构体定义 { int num;

char name[10]; char birthday[10]; int Cyuyan; int shujujiegou; struct student *next; }; struct student *creat_by_input(); struct student *get_last_student(struct student *head); struct student *Print_menu_main() //主菜单 { printf(\

*********************************************************************\\n\

printf(\ | 1.........输入学生信息 | \\n\

printf(\ | 2.........输出学生信息 | \\n\

printf(\ | 3.........查找学生信息 | \\n\

printf(\ | 4.........修改学生信息 | \\n\

printf(\ | 5.........插入学生信息 | \\n\

printf(\ | 6.........删除学生信息 | \\n\

printf(\ | 7.........排序学生信息 | \\n\

printf(\ | 0.........退出系统 | \\n\

printf(\ |_ _ _ _ _ _ _ _ _ _ _ _ _ | \\n\} struct student *print_table_head() { printf(\ printf(\ 学号 | 姓名 | 出生日期 | c成绩 |数据结构成绩 |\\n\ printf(\ }

struct student *print_table_row(struct student *p) { printf(\jiegou);

} void print_table_bottom() { printf(\ } struct student * Creat_stu_record() //建立链表 { struct student *plaststu=NULL,*pnewstu; char continue_input='N'; struct student *head=NULL; while(1) { if(head==NULL) { head=creat_by_input(); print_table_head(); print_table_row(head); print_table_bottom(); } else { pnewstu=creat_by_input(); print_table_head(); print_table_row(pnewstu); print_table_bottom(); plaststu=get_last_student(head); plaststu->next=pnewstu;} printf(\是否继续输入学生信息?(Y 继续,N 返回菜单)\\n\ getchar(); continue_input=getchar(); if(continue_input=='n'||continue_input=='N') { system(\ Print_menu_main(); break; } } return head; }

struct student *creat_by_input() { struct student *pnewstu=(struct student *)malloc(sizeof(struct student)); printf(\请输入学生信息\\n\ printf(\学号:\ printf(\姓名:\ printf(\出生年月:\ printf(\请输入学生成绩\\n\ printf(\语言:\ printf(\数据结构:\ pnewstu->next=NULL; return pnewstu; } struct student *get_last_student(struct student *p ) { if(p->next==NULL) return p; else return get_last_student(p->next); }

void Print_Stu_Doc(struct student *head) { struct student *p; char r; print_table_head(); if(head==NULL) { printf(\ } for(p=head;p;p=p->next) { printf(\jiegou);

printf(\ printf(\按Enter键返回主菜单)\\n\ getchar(); r=getchar(); if(r!='1') { system(\ Print_menu_main(); } else {

system(\ Print_menu_main(); } }

struct student *search_by_name(struct student *head)//按姓名查找 { char name[10]; struct student *p=head; char continue_input; /*int isfound=0;*/ printf(\请输入要查找的姓名:\ scanf(\ printf(\查找%s\\n\ print_table_head(); while(p!=NULL) { if(strcmp(p->name,name)==0) { print_table_row(p); p=p->next; /* isfound=1; */ break; } p=p->next; } print_table_bottom(); printf(\是否继续查找?(Y 继续;N 返回主菜单)\\n\ getchar(); continue_input=getchar(); if(continue_input=='n'||continue_input=='N') { system(\ Print_menu_main(); } else search_by_name(head); }

struct student * search_by_id(struct student *head)//按学号查找 { int id; struct student *p=head; char continue_input;

/*int isfound=0;*/ printf(\请输入要查找的学号:\ scanf(\ printf(\查找%d\\n\ print_table_head(); while(p!=NULL) { if(p->num==id) { print_table_row(p); p=p->next; /*isfound=1;*/ break; } p=p->next; } print_table_bottom(); printf(\是否继续查找?(Y 继续;N 返回主菜单)\\n\ getchar(); continue_input=getchar(); if(continue_input=='n'||continue_input=='N') { system(\ Print_menu_main(); } else search_by_id(head); return head; }

struct student*modify_record_by_id(struct student*head)//按学号修改 { struct student *p=head; int id; char continue_input; printf(\请输入要修改的学生的学号:\\n\ scanf(\ while(p!=NULL) { if(p->num==id) break; p=p->next; } if(p==NULL) printf(\抱歉,没有学号为%d的学生\\n\

else { printf(\请输入学生信息:\\n\ printf(\学号:\ printf(\姓名:\ printf(\出生年月:\ printf(\请输入学生成绩:\\n\ printf(\语言:\ printf(\数据结构:\ print_table_head();print_table_row(p);print_table_bottom();} printf(\继续修改学生信息吗?Y 继续;N 返回主菜单\\n\ getchar(); continue_input=getchar(); if(continue_input=='y'||continue_input=='Y') creat_by_input(); else { system(\ Print_menu_main(); } return head; }

struct student*modify_record_by_name(struct student*head)//按姓名修改 { struct student*p=head; char name[10]; char continue_input; printf(\请输入要修改的学生的姓名:\\n\ scanf(\ while(p!=NULL) { if(strcmp(p->name,name)==0) break; p=p->next; } if(p==NULL) printf(\抱歉,没有姓名为%s的学生\\n\ else { printf(\请输入学生信息:\\n\ printf(\学号:\ printf(\姓名:\ printf(\出生年月:\ printf(\请输入学生成绩:\\n\ printf(\语言:\

printf(\数据结构:\ print_table_head();print_table_row(p);print_table_bottom();} printf(\继续修改学生信息吗?Y 继续;N 返回主菜单\\n\ getchar(); continue_input=getchar(); if(continue_input=='y'||continue_input=='Y') creat_by_input(); else { system(\ Print_menu_main(); } return head; }

struct student *insert_record(struct student *head)//插入 { struct student *ptr1; struct student *ptr,*stud; struct student *ptr2=head; char continue_input='N'; int id; printf(\请输入一个学号,在此之前插入学生信息:\ scanf(\

stud=creat_by_input(); ptr=stud; if(head==NULL) { head=ptr;head->next=NULL; } else if(head->num==id) { ptr->next=head; head=ptr; } else { while(ptr2!=NULL) { ptr1=ptr2; ptr2=ptr1->next; if(ptr2->num==id) { ptr1->next=ptr; ptr->next=ptr2; break;

} } } print_table_head(); print_table_row(ptr); print_table_bottom(); printf(\是否继续插入学生信息?(Y 继续 N 返回主菜单)\\n\ getchar(); continue_input=getchar(); if(continue_input=='y'||continue_input=='Y') return insert_record(head); else { system(\ Print_menu_main(); return head; } }

struct student *Delete_record_by_id( struct student *head)//按学号删除 { struct student *p=head,*ppre=NULL; int id; char continue_input; printf(\请输入要删除的学号:\ scanf(\ while(p!=NULL) { if(p->num==id) break; p=p->next; } if(p==NULL) printf(\抱歉,没有该学号的学生信息!\\n\ else { printf(\确定要删除学号为%d的学生的信息吗?(Y 确定;N 返回主菜单)\\n\

getchar(); continue_input=getchar(); if(continue_input=='y'||continue_input=='Y') { ppre=head; if(ppre==p)

{ head=p->next; printf(\ \\n\ free(p); } else { while(ppre!=NULL) { if(ppre->next==p) { ppre->next=p->next; free(p); break; } ppre=ppre->next; } } printf(\删除成功!\ } // Print_menu_main(); } printf(\继续删除学生信息吗?(Y 继续;N 返回主菜单)\ getchar(); continue_input=getchar(); if(continue_input=='y'||continue_input=='Y') Delete_record_by_id(head); else { system(\ Print_menu_main(); return head; } return 0; }

struct student *Delete_record_by_name( struct student *head)// 按姓名删除 { struct student *p=head,*ppre=NULL; char name[10]; char continue_input; printf(\请输入要删除的姓名:\ scanf(\ while(p!=NULL) { if(strcmp(p->name,name)==0) break; p=p->next;

} if(p==NULL) { printf(\抱歉,没有该姓名的学生信息!\\n\ goto end; } else printf(\确定要删除姓名为%s的学生的信息吗?(Y 确定;N 返回主菜单)\

printf(\ getchar(); continue_input=getchar(); if(continue_input=='y'||continue_input=='Y') { ppre=head; if(ppre==p) { head=p->next; free(p); } else { while(ppre!=NULL) { if(ppre->next==p) { ppre->next=p->next; free(p); break; } ppre=ppre->next; } } printf(\删除成功!\ } //else Print_menu_main(); end: printf(\继续删除学生信息吗?(Y 继续;N 返回主菜单)\ printf(\ getchar(); continue_input=getchar(); if(continue_input=='Y'||continue_input=='y') Delete_record_by_name(head); else { system(\ Print_menu_main();return head;

} return 0; }

struct student * Sorting_record_by_id(struct student *head)//按学号排序 { int i=0,j,k,r; struct student *pt1,*pt2,*pt,m; if(head==NULL) { printf(\现在无同学记录\\n\ printf(\按Enter键返回主菜单)\\n\ getchar(); r=getchar(); if(r!='1') { system(\ Print_menu_main(); } else { system(\ Print_menu_main(); } } else { pt1=head; pt2=head->next; for(pt=head;pt;pt=pt->next) i++; for(j=1;jnext; for(k=1;knum>pt2->num) { m=*pt1; *pt1=*pt2; *pt2=m; pt2->next=pt1->next; pt1->next=pt2; } pt1=pt2;

pt2=pt1->next; } } } print_table_head(); for(pt=head;pt;pt=pt->next) { printf(\hujujiegou);

printf(\ return head; }

int main() { struct student *head=NULL; struct student *p; int choice;int select;char m;char r; system(\ printf(\ \\n\

printf(\ \\n\

printf(\ 欢迎使用学生成绩管理系统! \\n\

printf(\ \\n\

printf(\^^^^^^^^^^\\n\

printf(\ \\n\

printf(\ printf(\请按照提示信息完成操作\\n\ Print_menu_main(); printf(\ \\n\

printf(\ printf(\ \\n\

printf(\ while(choice!=0)

{ printf(\请选择所要执行的操作:\\n\start:if(scanf(\ { if(choice>7||choice<0) { printf(\请输入0到7的数字,选择所要执行的操作:\\n\ goto start; } else goto next; } if(scanf(\ { printf(\请输入0到7的数字,选择所要执行的操作:\\n\ goto start; }

next:switch(choice) { case 1:system(\ break; case 2:system(\ break; case 3:system(\ printf(\请选择查找方式:1 按姓名查找; 2 按学号查找;3 返回主菜单\ printf(\ scanf(\ switch(select) { case 1:search_by_name(head);break; case 2:search_by_id(head);break; case 3:system(\ };break; case 4:system(\请输入修改方式:1 按学号修改;2 按姓名修改; 3 返回主菜单\

printf(\ scanf(\ switch(select) { case 1:system(\ case 2:system(\ case 3:system(\ } break; case 5:system(\

case 6:system(\ printf(\请输入删除方式:1 按学号删除;2 按姓名删除; 3 返回主菜单\\n\ scanf(\ switch(select) { case 1:head=Delete_record_by_id(head);break; case 2:head=Delete_record_by_name(head);break; case 3:Print_menu_main();break; } break; case 7:system(\ Sorting_record_by_id(head); printf(\按Enter键返回主菜单)\\n\ getchar(); r=getchar(); if(r!='1') { system(\ Print_menu_main(); } else { system(\ Print_menu_main(); } break; break; case 0:system(\ printf(\ \\n\

printf(\ printf(\^-^ ^-^ ^-^ ^-^ ^-^ 谢谢使用 ^-^ ^-^ ^-^ \\n\

printf(\ \\n\

break; } } }

三:代码

第一部分: public class main {

^-^ ^-^!

}

public static void main(String[] args) { zhuchuangkou win=new zhuchuangkou(); }

第二部分主界面: import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*;

public class zhuchuangkou extends Frame implements ActionListener{

Button button1,button2,button3,button4,tuichu; Panel p1,p2,p3; Label l1,l2,l3; TextField a1,a2; Box b1,b2,b3,b4,b5; ss s;

zhuchuangkou(){

button1=new Button(\登陆\button2=new Button(\删除\button3=new Button(\修改\button4=new Button(\添加\tuichu=new Button(\退出\

p1=new Panel(); p2=new Panel(); p3=new Panel();

l1=new Label(\学生成绩管理\l1.setFont(new Font(\宋体\l1.setBackground(Color.green); l2=new Label(\登录名\l3=new Label(\密码\a1=new TextField(10);

a2=new TextField(10); a2.setEchoChar('*');

b1=Box.createVerticalBox(); b1.add(l2);

b1.add(Box.createVerticalStrut(8)); b1.add(l3);

b2=Box.createVerticalBox(); b2.add(a1);

b2.add(Box.createVerticalStrut(8)); b2.add(a2);

b4=Box.createHorizontalBox(); b4.add(button1);

b4.add(Box.createHorizontalStrut(10)); b4.add(tuichu);

b3=Box.createHorizontalBox(); b3.add(b1);

b3.add(Box.createHorizontalStrut(10)); b3.add(b2);

b5=Box.createVerticalBox(); b5.add(b3);

b5.add(Box.createVerticalStrut(8)); b5.add(b4);

button1.addActionListener(this); button2.addActionListener(this); button3.addActionListener(this); button4.addActionListener(this);

tuichu.addActionListener(this);

p1.add(l1); p2.add(b5);

}

add(p1,BorderLayout.NORTH); add(p2,BorderLayout.CENTER); add(p3,BorderLayout.PAGE_END); addWindowListener(new WindowAdapter(){ });

setBackground(Color.RED); setBounds(10, 10, 1000, 500); setVisible(true); validate();

public void windowClosing(WindowEvent e){ }

dispose();

public void actionPerformed(ActionEvent e){

if(e.getSource()==tuichu){ }

if(e.getSource()==button1){ }

if(a1.getText().equals(\ } else{ }

System.out.print(\new chuankou();

System.out.println(\dispose(); System.exit(0);

} }

第三部分选择操作: import java.awt.*;

import java.awt.event.*; import javax.swing.*;

import javax.swing.border.*;

public class zhuchuangkou extends Frame implements ActionListener{ Button button1,button2,button3,button4,tuichu; Panel p1,p2,p3; Label l1,l2,l3; TextField a1,a2; Box b1,b2,b3,b4,b5; ss s; zhuchuangkou(){ button1=new Button(\登陆\ button2=new Button(\删除\ button3=new Button(\修改\ button4=new Button(\添加\ tuichu=new Button(\退出\ p1=new Panel(); p2=new Panel(); p3=new Panel(); l1=new Label(\学生成绩管理\ l1.setFont(new Font(\宋体\ l1.setBackground(Color.green); l2=new Label(\登录名\ l3=new Label(\密码\ a1=new TextField(10); a2=new TextField(10); a2.setEchoChar('*'); b1=Box.createVerticalBox(); b1.add(l2); b1.add(Box.createVerticalStrut(8)); b1.add(l3); b2=Box.createVerticalBox(); b2.add(a1); b2.add(Box.createVerticalStrut(8)); b2.add(a2);

b4=Box.createHorizontalBox(); b4.add(button1); b4.add(Box.createHorizontalStrut(10)); b4.add(tuichu); b3=Box.createHorizontalBox(); b3.add(b1); b3.add(Box.createHorizontalStrut(10)); b3.add(b2); b5=Box.createVerticalBox(); b5.add(b3); b5.add(Box.createVerticalStrut(8)); b5.add(b4); button1.addActionListener(this); button2.addActionListener(this); button3.addActionListener(this); button4.addActionListener(this); tuichu.addActionListener(this); p1.add(l1); p2.add(b5); add(p1,BorderLayout.NORTH); add(p2,BorderLayout.CENTER); add(p3,BorderLayout.PAGE_END); addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ dispose(); } }); setBackground(Color.RED); setBounds(10, 10, 1000, 500); setVisible(true); validate(); }

public void actionPerformed(ActionEvent e){ if(e.getSource()==tuichu){ System.exit(0); } if(e.getSource()==button1){

}

}

}

if(a1.getText().equals(\ new chuankou(); System.out.println(\ dispose(); } else{ System.out.print(\}

第四部分查询界面实现: import java.awt.*; import java.awt.event.*; import java.sql.*;

import javax.swing.JOptionPane;

public class ss extends Frame implements TextListener,ActionListener{

Button xunzhao; TextField input; TextArea show; String s; int k;

Connection con;

Statement sql; int sum=0; ResultSet rs;

ss(){

Panel p=new Panel(); xunzhao= new Button(\查找\input= new TextField(10); show= new TextArea(6,43); p.add(new Label(\输入学号\

}

p.add(input); p.add(xunzhao);

xunzhao.addActionListener(this); show.addTextListener(this); show.setEditable(false); add(p,BorderLayout.NORTH); add(show,BorderLayout.CENTER);

setBounds(10,30,500,200); setVisible(true); validate();

addWindowListener(new WindowAdapter(){ });

public void windowClosing(WindowEvent e){ }

dispose();

public void actionPerformed(ActionEvent ee) {

boolean boo=true; s=input.getText(); k=Integer.parseInt(s);

try { Class.forName(\

catch(ClassNotFoundException eee) { System.out.println(\;}

try { con=DriverManager.getConnection(\ sql=con.createStatement();

rs=sql.executeQuery(\ while(rs.next()) {

int number=rs.getInt(\

String name=rs.getString(\ String date=rs.getString(\

int math=rs.getInt(\

int english=rs.getInt(\ if(number==k) { boo=false;

show.setText(null);

show.append(\学号:\ 姓名:\ 出生:\数学 \英语 \

} } con.close(); if(boo){ } }

catch(SQLException eee) { System.out.println(eee); } }

第五部分删除:

import java.awt.*;

import java.awt.event.*; import java.sql.*;

import javax.swing.JOptionPane;

public class shanchu extends Frame implements TextListener,ActionListener{ Button xunzhao; TextField input; TextArea show; String s; int k,s1,j; Connection con; Statement sql; int sum=0; ResultSet rs;

show.append(\

JOptionPane.showMessageDialog(this, \你输入的学号不存在\

}

shanchu(){ Panel p=new Panel(); xunzhao= new Button(\删除\ input= new TextField(10); show= new TextArea(6,43); p.add(new Label(\输入要删除的\学号\ p.add(input); p.add(xunzhao); xunzhao.addActionListener(this); show.addTextListener(this); show.setEditable(false); add(p,BorderLayout.NORTH); add(show,BorderLayout.CENTER); setBounds(10,30,500,200); setVisible(true); validate(); addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ dispose(); } }); } public void actionPerformed(ActionEvent ee) { boolean boo=true; s=input.getText(); k=Integer.parseInt(s); String m,dir; try { Class.forName(\ }

catch(ClassNotFoundException eee) { System.out.println(\ }

try { con=DriverManager.getConnection(\

sql=con.createStatement();

rs=sql.executeQuery(\ while(rs.next())

{int number=rs.getInt(2);

String name=rs.getString(3);

String date=rs.getString(\ int math=rs.getInt(\ int english=rs.getInt(\

if(number==k){ show.setText(\你删除了:\ show.append(\学号:\ 姓名:\ 出生:\

数学 \英语 \

show.append(\ m=\ sql.executeUpdate(m); } }

con.close(); }

catch(SQLException e) { System.out.println(e); } } }

第六部分修改: import java.awt.*;

import java.awt.event.*; import java.sql.*;

import javax.swing.JOptionPane;

public class xiugai extends Frame implements TextListener,ActionListener{ Button charu; TextField input1,input2,input3,input4,input5,input6; TextArea show; Panel p1,p2; int k,s1,j; Connection con; Statement sql; int sum=0; ResultSet rs; xiugai(){ p1=new Panel(); p2=new Panel(); charu= new Button(\修改\ input1= new TextField(10); input2= new TextField(10); input3= new TextField(10); input4= new TextField(10); input5= new TextField(10); input6= new TextField(10); show= new TextArea(6,43); p1.add(new Label(\请输入要修改的学号\

p1.add(new Label(\ p1.add(input1); p2.add(new Label(\请输入修改的数据\ p2.add(new Label(\ p2.add(input2); p2.add(new Label(\ p2.add(input3); p2.add(new Label(\ p2.add(input4); p2.add(new Label(\ p2.add(input5); p2.add(charu); charu.addActionListener(this); show.addTextListener(this); show.setEditable(false); add(p1,BorderLayout.NORTH); add(p2,BorderLayout.CENTER); setBounds(10,30,1200,200); setVisible(true); validate(); addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ dispose(); } }); }

public void actionPerformed(ActionEvent ee) { boolean boo=true; String s0,s1,s2,s3,s4,s5,insert1,recode,name,date; int m0,m1,m2,m3,number,math,english; s1=input1.getText(); m1=Integer.parseInt(s1); number=m1; s4=input4.getText(); m2=Integer.parseInt(s4); math=m2; s5=input5.getText(); m3=Integer.parseInt(s5); english=m3;

try { Class.forName(\ }

catch(ClassNotFoundException eee) { System.out.println(\ }

try { con=DriverManager.getConnection(\

sql=con.createStatement();

recode=\+english+\

insert1=\TE chengjibiao SET math=\

WHERE number=\

sql.executeUpdate(insert1); } catch(SQLException e) { System.out.println(e); } } }

第七部分添加: import java.awt.*;

import java.awt.event.*; import java.sql.*;

import javax.swing.JOptionPane;

public class charu extends Frame implements TextListener,ActionListener{ Button charu; TextField input1,input2,input3,input4,input5,input6; TextArea show; int k,s1,j; Connection con; Statement sql; int sum=0; ResultSet rs; charu(){ Panel p=new Panel(); charu= new Button(\插入\ input1= new TextField(10); input2= new TextField(10); input3= new TextField(10); input4= new TextField(10); input5= new TextField(10); input6= new TextField(10); show= new TextArea(6,43); p.add(new Label(\请输入要插入的数据\ p.add(new Label(\

}

p.add(input6);

p.add(new Label(\p.add(input1);

p.add(new Label(\p.add(input2);

p.add(new Label(\p.add(input3);

p.add(new Label(\p.add(input4);

p.add(new Label(\p.add(input5);

p.add(charu);

charu.addActionListener(this); show.addTextListener(this); show.setEditable(false);

add(p,BorderLayout.NORTH);

add(show,BorderLayout.CENTER);

setBounds(10,30,1200,200); setVisible(true); validate();

addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ dispose(); } });

public void actionPerformed(ActionEvent ee) { boolean boo=true;

String s0,s1,s2,s3,s4,s5,insert1,recode,name,date; int m0,m1,m2,m3,number,math,english; s0=input5.getText(); m0=Integer.parseInt(s0); s1=input1.getText(); m1=Integer.parseInt(s1); number=m1;

s2=input2.getText(); name=s2;

s3=input3.getText(); date=s3;

s4=input4.getText(); m2=Integer.parseInt(s4); math=m2;

s5=input5.getText();

m3=Integer.parseInt(s5); english=m3; try { Class.forName(\ }

catch(ClassNotFoundException eee) { System.out.println(\ }

try { con=DriverManager.getConnection(\ sql=con.createStatement();

recode=\+english+\

insert1=\ALUES \

sql.executeUpdate(insert1);

show.setText(\你插入了:\

show.append(\学号:\ 姓名:\ 出生:\数学

\英语 \

show.append(\ }

catch(SQLException e) { System.out.println(e); JOptionPane.showMessageDialog(this, \你输入的不正确\ } } }

四:运行效果

五总结:

本次课程设计,让我获益匪浅,不仅更深入的了解Java这门学科,更使自己有了继续探索的兴趣。

于个人而言,在程序设计的过程中,我深感“认真严谨”这个词的重要性,一点点小的马虎,便会导致整个程序不能正常运行。在今后的学习中,我定将“认真严谨时刻作为自的谨言。与此同时,本小组成员的互帮互助,让我体会到了

团结的力量,而更让人难以忘怀的是在热烈讨论问题时,那激情横溢的场面。总之,此次课程设计在我的学生生涯中启上了至关重要的作用。

最后,真诚的感谢彭老师的指导和教诲。

本文来源:https://www.bwwdw.com/article/e4br.html

Top