首页 热点专区 义务教育 高等教育 出国留学 考研考公
您的当前位置:首页正文

JAVA学生信息管理系统实验报告

2023-06-25 来源:要发发教育


JAVA程序设计实验报告

学 号: 姓 名: 班 级:

实验、Java课程设计--------学生信息管理系统

一、实验目的

1. 掌握Java基本语法 2. 理解面向对象编程特点 3. 理解Java I/O编程 4. 掌握Java图形界面编程

5. 掌握Java与不同数据库进行连接

二、预习内容

Java的基本语法知识、类和对象、Java Swing图形界面编程、Java I/O处理以及Java与数据库连接操作

三、实验设备与环境

通过局域网互联,安装Windows 2000/XP操作系统环境的JDK 1.6,my eclipse或者EditPlus编程工具。并安装MySQL数据库

四、实验内容

编写并调试运行Java程序,进行设计,掌握Java开发的基础。

五、实验任务

设计学生信息管理系统。要求包括

1. 登陆模块:设立超级管理员权限,用户可以根据不同的权限登陆系统,超级管理员可以对学生信息进行增、删、改、查操作。而普通用户只可以查找学生信息。

2. 包括学生添加信息模块、学生信息删除模块、学生信息修改模块和学生信息查询模块

3.对于管理员,可以对管理员进行添加、删除以及修改密码等操作。

六、实验报告(要求独立完成参考程序的代码、编译、调试与运行)

1、程序清单: 1.1程序模块清单 package Pan;

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

import java.awt.Component;

import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.event.InputEvent; import java.awt.event.ItemListener; import java.awt.event.KeyEvent; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.util.*; import java.awt.Color;

import java.text.DecimalFormat; import java.sql.*; import java.sql.Date; import java.awt.*; import java.util.Vector; public class Res { /**

* @param args */

public static void main(String[] args) {

FirstWindow win =new FirstWindow(\"学生信息管理系统\"); } } class

FirstWindow

extends

JFrame

implements

ActionListener {

JMenuBar menubar;

JMenu menu1,menu2,menu3,menu4;

public final JMenuItem a11,a12,a13,a14,a15,a16,a17; public final JMenuItem a21,a22,a23,a24; public final JMenuItem a3; public final JMenuItem a4; public final JButton btn; JPanel pnl; JLabel label; boolean flag;

FirstWindow(String s) {

setTitle(s);

setSize(400,400); setLocation(100,100); setVisible(true);

setDefaultCloseOperation(3); pnl=new JPanel();

this.getContentPane().add(pnl); pnl.setLayout(new BorderLayout());

label=new JLabel(\"欢迎使用学生管理系统\

label.setForeground(Color.red); pnl.add(label,BorderLayout.CENTER); menubar=new JMenuBar(); menu1=new JMenu(\"使用\"); menu2=new JMenu(\"用户管理\"); menu3=new JMenu(\"帮助\"); menu4=new JMenu(\"退出\");

a11=new JMenuItem(\"管理员登录\"); a12=new JMenuItem(\"查询学生信息\"); a13=new JMenuItem(\"更改学生信息\"); a14=new JMenuItem(\"删除学生信息\"); a15=new JMenuItem(\"添加学生信息\"); a16=new JMenuItem(\"超级管理员登录\");

a17=new JMenuItem(\"普通学生登录\"); a11.setEnabled(true); a16.setEnabled(true); a17.setEnabled(true); a12.setVisible(false); a13.setVisible(false); a14.setVisible(false); a15.setVisible(false);

a21=new JMenuItem(\"添加用户\"); a22=new JMenuItem(\"删除用户\"); a23=new JMenuItem(\"更改用户\"); a24=new JMenuItem(\"修改密码\"); a21.setEnabled(false); a22.setEnabled(false); a23.setEnabled(false); a24.setEnabled(false);

a3=new JMenuItem(\"系统介绍\"); a3.setEnabled(true); a4=new JMenuItem(\"退出\"); a4.setEnabled(true);

btn=new JButton(\"再次确认登陆\"); pnl.add(btn,BorderLayout.EAST);

btn.setSize(10,10); menu1.add(a11); menu1.addSeparator(); menu1.add(a16); menu1.addSeparator(); menu1.add(a17); menu1.addSeparator(); menu1.add(a12); menu1.addSeparator(); menu1.add(a13); menu1.addSeparator(); menu1.add(a14); menu1.addSeparator(); menu1.add(a15); menu1.addSeparator();

menu2.add(a21); menu2.addSeparator(); menu2.add(a22); menu2.addSeparator(); menu2.add(a23); menu2.addSeparator();

menu2.add(a24); menu2.addSeparator(); menu3.add(a3); menu3.addSeparator(); menu4.add(a4); menubar.add(menu1); menubar.add(menu2); menubar.add(menu3); menubar.add(menu4); setJMenuBar(menubar); a11.addActionListener(this); a12.addActionListener(this); a13.addActionListener(this); a14.addActionListener(this); a15.addActionListener(this); a16.addActionListener(this); a17.addActionListener(this); a21.addActionListener(this); a22.addActionListener(this); a23.addActionListener(this); a24.addActionListener(this); a3.addActionListener(this);

a4.addActionListener(this); btn.addActionListener(this); }

public void setColor(Color black) { // TODO Auto-generated method stub }

public void actionPerformed(ActionEvent event) {

Object temp=new Object(); temp=event.getSource(); if(temp==a11) {

Login login=new Login();

login.Login(); } if(temp==a12) {

ShowStu show=new ShowStu(); show.ShowStu(); }

if(temp==a13) {

AlterStu alter=new AlterStu(); alter.AlterStu(); }

if(temp==a14) {

DeleteStu delete=new DeleteStu(); delete.DeleteStu(); }

if(temp==a15) {

AddStu add=new AddStu(); add.AddStu();

}

if(temp==a16) {

superlog superlog=new superlog(); superlog.superlog(); }

if(temp==a17) {

stuLogin stu=new stuLogin(); stu.stuLogin(); a12.setVisible(true); }

if(temp==a21) {

AddUser add=new AddUser(); add.AddUser(); }

if(temp==a22) {

DeleteUser delete=new DeleteUser();

delete.DeleteUser(); }

if(temp==a23) {

AlterUser alter=new AlterUser(); alter.AlterUser(); }

if(temp==a24) {

AlterPword pword=new AlterPword(); pword.AlterPword(); }

if(temp==a3) {

SystemHelp help=new SystemHelp(); help.SystemHelp(); }

if(temp==a4) {

SystemExit exit1=new SystemExit(); exit1.SystemExit();

}

if(temp==btn) {

Connection con; Statement st; Statement st1; ResultSet rs,rs1; try {

Class.forName(\"sun.jdbc.odbc.JdbcOdbcDriver\"); }

catch(ClassNotFoundException e) {

System.out.println(\"\" + e); } try {

con=DriverManager.getConnection(\"jdbc:odbc:pan\;

st=con.createStatement(); st1=con.createStatement();

rs=st.executeQuery(\"SELECT * FROM Login\"); rs1=st1.executeQuery(\"SELECT superlog\");

*

FROM

if(rs.next()) {

a23.setEnabled(true); a24.setEnabled(true); login.Clear(); }

if(rs1.next()) {

a13.setVisible(true); a14.setVisible(true); a15.setVisible(true); a12.setVisible(true); a21.setEnabled(true);

a22.setEnabled(true); Login login=new Login(); a12.setVisible(true);

superlog superlog=new superlog(); superlog.Cclear(); }

con.close(); catch(SQLException e) {

} } } } 主页面

}

System.out.println(e);

class Login {

void Login() {

final JFrame loginframe=new JFrame(\"登陆界面\"); loginframe.setBounds(200,200,400,500); loginframe.setVisible(true); loginframe.setResizable(true); loginframe.setLayout(null);

final JTextField text1=new JTextField(10);

final JPasswordField(10);

JPasswordField text2=new

JButton btn1=new JButton(\"登陆\"); JButton btn2=new JButton(\"取消\"); JLabel label1=new JLabel(\"用户名\"); JLabel label2=new JLabel(\"密码\"); loginframe.add(btn1); loginframe.add(btn2); loginframe.add(text1); loginframe.add(text2); loginframe.add(label1); loginframe.add(label2);

label1.setBounds(80, 100, 50, 50); label2.setBounds(80, 200, 50, 50); btn1.setForeground(Color.black); btn2.setForeground(Color.black); text1.setBounds(150, 100, 200, 30); text2.setBounds(150, 200, 200, 30); btn1.setBounds(100, 300, 100, 60); btn2.setBounds(200, 300, 100, 60);

btn1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent event)

{

String name=text1.getText(); String password=text2.getText(); try {

Class.forName(\"sun.jdbc.odbc.JdbcOdbcDriver\"); }

catch(ClassNotFoundException e) {

System.out.println(\"\" + e); } try {

Connection con; Statement sql,st; ResultSet rs;

con=DriverManager.getConnection(\"jdbc:odbc:pan\;

sql=con.createStatement(); st=con.createStatement(); rs=sql.executeQuery(\"SELECT username,password username='\"+name+\"'\");

if(!rs.next())

{JOptionPane b=new JOptionPane(); b.showMessageDialog(null,\"账号有误\" ,\"消息对话框\ } else

{String username=rs.getString(1); String pass=rs.getString(2);

if( Integer.parseInt(password)==Integer.parseInt(pass) )

FROM

users

where

{

st.executeUpdate(\"INSERT Login VALUES('\"+username+\"','\"+pass+\"')\"); loginframe.dispose();

JOptionPane b=new JOptionPane(); b.showMessageDialog(null,\"登录成功\" ,\"消息对话框\ } else {

text1.setText(\"\");

text2.setText(\"\");

JOptionPane a=new JOptionPane();

a.showMessageDialog(null,\"您的账户名

\

框INTO

\" ,JOptionPane.INFORMATION_MESSAGE); } }

}

catch(SQLException e) {

System.out.println(e); }

} });

btn2.addActionListener(new ActionListener() { public event) {

loginframe.dispose(); } }); } void Clear() {

Connection con; Statement st; ResultSet rs;

void

actionPerformed(ActionEvent

try {

Class.forName(\"sun.jdbc.odbc.JdbcOdbcDriver\"); }

catch(ClassNotFoundException e) {

System.out.println(\"\" + e); } try {

con=DriverManager.getConnection(\"jdbc:odbc:pan\;

st=con.createStatement();

st.executeUpdate(\"DELETE FROM Login\");

con.close(); }

catch(SQLException e) {

System.out.println(e); } } }

管理员登陆与权限

class superlog {

superlog() {

final JFrame loginframe=new JFrame(\"登陆界面\"); loginframe.setBounds(200,200,400,500); loginframe.setVisible(true); loginframe.setResizable(true); loginframe.setLayout(null);

final JTextField text1=new JTextField(10); final JPasswordField text2=new JPasswordField(10);

JButton btn1=new JButton(\"登陆\"); JButton btn2=new JButton(\"取消\"); JLabel label1=new JLabel(\"\

JLabel label2=new JLabel(\"密码\ loginframe.add(btn1); loginframe.add(btn2); loginframe.add(text1); loginframe.add(text2); loginframe.add(label1);

超级用户名

loginframe.add(label2);

label1.setBounds(80, 100, 100, 50); label2.setBounds(80, 200, 100, 50); btn1.setForeground(Color.black); btn2.setForeground(Color.black); text1.setBounds(150, 100, 200, 30); text2.setBounds(150, 200, 200, 30); btn1.setBounds(100, 300, 100, 60); btn2.setBounds(200, 300, 100, 60);

btn1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent event) {

String name=text1.getText(); @SuppressWarnings(\"deprecation\") String password=text2.getText(); try

{

Class.forName(\"sun.jdbc.odbc.JdbcOdbcDriver\"); }

catch(ClassNotFoundException e) {

System.out.println(\"\" + e); } try {

Connection con; Statement sql; ResultSet rs;

con=DriverManager.getConnection(\"jdbc:odbc:pan\;

sql=con.createStatement(); rs=sql.executeQuery(\"SELECT Cusername,Cpassword Cusername='\"+name+\"'\"); if(!rs.next())

FROM

super

where

{

JOptionPane b=new JOptionPane(); b.showMessageDialog(null,\"超级账号错误\" ,\"消息对话框\ } else

{String username=null; String pass=null;

username=rs.getString(1); pass=rs.getString(2);

if( Integer.parseInt(password)==Integer.parseInt(pass) )

{

sql.executeUpdate(\"INSERT superlog VALUES('\"+username+\"',\"+\"'\"+pass+\"')\"); JOptionPane b=new JOptionPane(); b.showMessageDialog(null,\"登录成功\" ,\"消息对话框\

INTO

loginframe.dispose(); } else {

text1.setText(\"\"); text2.setText(\"\");

JOptionPane a=new JOptionPane(); a.showMessageDialog(null,\"您的账户名或者

\

\" ,JOptionPane.INFORMATION_MESSAGE); } }

}

catch(SQLException e) {

System.out.println(e); }

} });

btn2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent event) {

loginframe.dispose(); } }); }

public void superlog() {

// TODO Auto-generated method stub }

void Cclear() {

Connection con; Statement st; ResultSet rs; try {

Class.forName(\"sun.jdbc.odbc.JdbcOdbcDriver\"); }

catch(ClassNotFoundException e) {

System.out.println(\"\" + e); } try {

con=DriverManager.getConnection(\"jdbc:odbc:pan\;

st=con.createStatement();

st.executeUpdate(\"DELETE FROM superlog\");

con.close(); }

catch(SQLException e) {

System.out.println(e); } } }

超级管理员登陆界面与权限

class stuLogin {

void stuLogin() {

final JFrame loginframe=new JFrame(\"登陆界面\"); loginframe.setBounds(200,200,400,500); loginframe.setVisible(true); loginframe.setResizable(true); loginframe.setLayout(null);

final JTextField text1=new JTextField(15); final JPasswordField text2=new JPasswordField(15);

JButton btn1=new JButton(\"登陆\"); JButton btn2=new JButton(\"取消\"); JLabel

label1=new

JLabel(\"

\

JLabel label2=new JLabel(\"密码\ loginframe.add(btn1); loginframe.add(btn2); loginframe.add(text1); loginframe.add(text2); loginframe.add(label1);

loginframe.add(label2);

label1.setBounds(80, 100, 100, 50); label2.setBounds(80, 200, 100, 50); btn1.setForeground(Color.black); btn2.setForeground(Color.black); text1.setBounds(150, 100, 200, 30); text2.setBounds(150, 200, 200, 30); btn1.setBounds(100, 300, 100, 60); btn2.setBounds(200, 300, 100, 60);

btn1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent event) {

String name=text1.getText(); String password=text2.getText(); try {

Class.forName(\"sun.jdbc.odbc.JdbcOdbcDriver\"); }

catch(ClassNotFoundException e) {

System.out.println(\"\" + e); } try {

Connection con; Statement sql; ResultSet rs;

con=DriverManager.getConnection(\"jdbc:odbc:pan\;

sql=con.createStatement(); rs=sql.executeQuery(\"SELECT

sname,sphone FROM student where sname='\"+name+\"' AND sphone='\"+password+\"'\"); if(rs.next()) {

JOptionPane a=new JOptionPane(); a.showMessageDialog(null,\"登陆成功

\消息对话框\" ,JOptionPane.INFORMATION_MESSAGE); loginframe.dispose(); } else {

text1.setText(\"\"); text2.setText(\"\");

JOptionPane a=new JOptionPane(); a.showMessageDialog(null,\"您的账户名

\

\" ,JOptionPane.INFORMATION_MESSAGE); }

con.close(); }

catch(SQLException e) {

System.out.println(e); } } });

btn2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent event) {

loginframe.dispose(); } }); } }

普通学生登陆与权限

class ShowStu

{

void ShowStu() {

JFrame frame1=new JFrame(\"学生信息窗口\"); frame1.setBounds(300,300,500,400); frame1.setDefaultCloseOperation(2); JTable table; Object a[][]=null;

Object name[]={\"学号\姓名\年龄\性别\籍贯\电话\

Connection con; Statement st; ResultSet rs; try {

Class.forName(\"sun.jdbc.odbc.JdbcOdbcDriver\"); }

catch(ClassNotFoundException e) {

System.out.println(\"\" + e); } try {

con=DriverManager.getConnection(\"jdbc:odbc:pan\\");

st=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);

rs=st.executeQuery(\"SELECT * FROM student\"); rs.last();

int lastnumber=rs.getRow(); a=new Object[lastnumber][6]; int i=0;

rs.beforeFirst(); while(rs.next()) {

a[i][0]=rs.getString(1); a[i][1]=rs.getString(2); a[i][2]=rs.getString(3);

a[i][3]=rs.getString(4); a[i][4]=rs.getString(5); a[i][5]=rs.getString(6); i++; }

con.close(); }

catch(SQLException e) {

System.out.println(e); }

table=new JTable(a,name);

frame1.setLayout(new BorderLayout()); frame1.add(new

JScrollPane(table),BorderLayout.CENTER); frame1.setVisible(true); frame1.validate(); } }

class AlterStu {

void AlterStu() {

JFrame deleteframe=new JFrame(\"更改学生信息\"); deleteframe.setLayout(null);

JLabel label=new JLabel(\"需要修改的学生学号\

deleteframe.setVisible(true);

deleteframe.setBounds(350,350,450,350); JButton btn=new JButton(\"确定\"); deleteframe.add(label);

label.setForeground(Color.red);

final JTextField text=new JTextField(10); text.setSize(100,60); deleteframe.add(text); deleteframe.add(btn);

label.setBounds(150, 50, 150, 20); text.setBounds(150, 100, 100, 20); btn.setBounds(150, 150, 100, 20);

btn.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent event) {

String sno=text.getText(); Connection con; Statement st; ResultSet rs; try {

Class.forName(\"sun.jdbc.odbc.JdbcOdbcDriver\"); }

catch(ClassNotFoundException e) {

System.out.println(e); } try {

con=DriverManager.getConnection(\"jdbc:odbc:pan\;

st=con.createStatement();

rs=st.executeQuery(\"SELECT * FROM student WHERE sno=+'\"+sno+\"'\"); if(rs==null) {

JOptionPane b=new JOptionPane(); b.showMessageDialog(null,\"该学生不存在\" ,\"消息对话框\ } else {

rs.next();

final String no1=rs.getString(1);

final String name1=rs.getString(2); final String age1=rs.getString(3); final String sex1=rs.getString(4); final String address1=rs.getString(5); final String phone1=rs.getString(6); JFrame addframe=new JFrame(\"修改学生信息\");

addframe.setDefaultCloseOperation(2); addframe.setBounds(400,200,450,600); addframe.setVisible(true); addframe.setResizable(true); addframe.validate(); addframe.setLayout(new BorderLayout());

Box basebox,box1,box2,box3,box4; basebox=Box.createHorizontalBox(); box1=Box.createVerticalBox(); box2=Box.createVerticalBox(); box3=Box.createVerticalBox(); box4=Box.createVerticalBox(); JLabel no=new JLabel(\"学号\"); JLabel name=new JLabel(\"姓名\");

JTextField(15); JTextField(15); JTextField(15);

JLabel age=new JLabel(\"年龄\");

box1.add(Box.createVerticalStrut(90)); box1.add(no);

box1.add(Box.createVerticalStrut(90)); box1.add(name);

box1.add(Box.createVerticalStrut(90)); box1.add(age);

JLabel sex=new JLabel(\"性别\"); JLabel address =new JLabel(\"籍贯\"); JLabel phone=new JLabel(\"电话\"); box3.add(Box.createVerticalStrut(90)); box3.add(sex);

box3.add(Box.createVerticalStrut(90)); box3.add(address);

box3.add(Box.createVerticalStrut(90)); box3.add(phone); final JTextField

notext=new

final JTextField

nametext=new

final JTextField

agetext=new

final JTextField(15); final JTextField(15); JTextField sextext=new

JTextField addresstext=new

JTextField(15);

final JTextField phonetext=new

box2.add(Box.createVerticalStrut(90)); box2.add(notext);

box2.add(Box.createVerticalStrut(90)); box2.add(nametext);

box2.add(Box.createVerticalStrut(90)); box2.add(agetext);

box4.add(Box.createVerticalStrut(90)); box4.add(sextext);

box4.add(Box.createVerticalStrut(90)); box4.add(addresstext);

box4.add(Box.createVerticalStrut(90)); box4.add(phonetext); basebox.add(box1); basebox.add(box2); basebox.add(box3); basebox.add(box4);

JLabel title=new JLabel(\"所要修改学生的基本信息\

JButton addbtn=new JButton(\"修改\");

addframe.add(title,BorderLayout.NORTH);

addframe.add(basebox,BorderLayout.CENTER);

addframe.add(addbtn,BorderLayout.SOUTH); notext.setText(no1); nametext.setText(name1); agetext.setText(age1); sextext.setText(sex1);

addresstext.setText(address1); phonetext.setText(phone1); addbtn.addActionListener(new ActionListener() { public

actionPerformed(ActionEvent event) {

Connection con;

void

Statement st; ResultSet rs;

String no2=notext.getText(); String name2=nametext.getText(); String age2=agetext.getText(); String sex2=sextext.getText(); String address2=addresstext.getText(); String phone2=phonetext.getText(); try {

Class.forName(\"sun.jdbc.odbc.JdbcOdbcDriver\"); }

catch(ClassNotFoundException e) {

System.out.println(e); } try {

con=DriverManager.getConnection(\"jdbc:odbc:pan\;

st=con.createStatement(); int ok=st.executeUpdate(\"UPDATE

student

SET

sno='\"+no2+\"',sname='\"+name2+\"',ssex='\"+sex2+\"',sage='\"+age2+\"',saddress='\"+address2+\"',sphone='\"+phone2+\"' WHERE sno='\"+no1+\"'\");

if(ok==1) {

JOptionPane JOptionPane();

b.showMessageDialog(null,\"修改成功\" ,\"消息对话框\ }

con.close(); }

catch(SQLException e)

b=new

} }); } }

{

System.out.println(e); } } }); }

con.close(); }

catch(SQLException e) {

System.out.println(e); }

class DeleteStu {

void DeleteStu() {

JFrame deleteframe=new JFrame(\"删除学生信息\"); deleteframe.setLayout(null);

JLabel label=new JLabel(\"请输入要删除学生的学号\

deleteframe.setVisible(true);

deleteframe.setBounds(300,300,400,300); JButton btn=new JButton(\"确定\"); deleteframe.add(label);

label.setForeground(Color.black);

final JTextField text=new JTextField(15); text.setSize(100,60); deleteframe.add(text); deleteframe.add(btn);

label.setBounds(150, 50, 150, 20); text.setBounds(150, 100, 100, 20); btn.setBounds(150, 150, 100, 20);

btn.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent event) {

Connection con; Statement st; ResultSet rs;

String sno=text.getText(); try {

Class.forName(\"sun.jdbc.odbc.JdbcOdbcDriver\"); }

catch(ClassNotFoundException e) {

System.out.println(e); } try {

con=DriverManager.getConnection(\"jdbc:odbc:pan\;

st=con.createStatement();

int ok= st.executeUpdate(\"DELETE FROM student WHERE sno='\"+sno+\"'\"); if(ok==1) {

JOptionPane b=new JOptionPane(); b.showMessageDialog(null,\"删除成功\" ,\"消息对话框\ }

rs=st.executeQuery(\"SELECT student\");

* FROM

\"+age+\" \"+sex+\" \"+address+\" \"+phone); while(rs.next()) {

String no=rs.getString(1);

String name=rs.getString(2); String age=rs.getString(3); String sex=rs.getString(4); String address=rs.getString(5); String phone=rs.getString(6); System.out.println(no+\" \"+

}

con.close(); }

catch(SQLException e) {

System.out.println(e); } }

name+\"

}); } }

class AddStu {

String sage; String ssex; String sno; String saddress; String sphone; String sname;

void AddStu() {

JFrame addframe=new JFrame(\"添加学生信息窗体\"); addframe.setDefaultCloseOperation(2); addframe.setBounds(400,200,400,500); addframe.setVisible(true); addframe.setResizable(true); addframe.validate();

addframe.setLayout(new BorderLayout()); Box basebox,box1,box2,box3,box4; basebox=Box.createHorizontalBox(); box1=Box.createVerticalBox(); box2=Box.createVerticalBox(); box3=Box.createVerticalBox(); box4=Box.createVerticalBox(); JLabel no=new JLabel(\"学号\"); JLabel name=new JLabel(\"姓名\"); JLabel age=new JLabel(\"年龄\");

box1.add(Box.createVerticalStrut(100));

box1.add(no);

box1.add(Box.createVerticalStrut(125)); box1.add(name);

box1.add(Box.createVerticalStrut(125)); box1.add(age);

JLabel sex=new JLabel(\"性别\"); JLabel address =new JLabel(\"籍贯\"); JLabel phone=new JLabel(\"电话\"); box3.add(Box.createVerticalStrut(100)); box3.add(sex);

box3.add(Box.createVerticalStrut(125)); box3.add(address);

box3.add(Box.createVerticalStrut(125)); box3.add(phone);

final JTextField notext=new JTextField(15); final JTextField nametext=new JTextField(15); final JTextField agetext=new JTextField(15); final JTextField sextext=new JTextField(15); final JTextField addresstext=new JTextField(15); final JTextField phonetext=new JTextField(15); box2.add(Box.createVerticalStrut(100)); box2.add(notext);

box2.add(Box.createVerticalStrut(100)); box2.add(nametext);

box2.add(Box.createVerticalStrut(100)); box2.add(agetext);

box4.add(Box.createVerticalStrut(100)); box4.add(sextext);

box4.add(Box.createVerticalStrut(100)); box4.add(addresstext);

box4.add(Box.createVerticalStrut(100)); box4.add(phonetext); basebox.add(box1); basebox.add(box2); basebox.add(box3); basebox.add(box4);

JLabel title=new JLabel(\"需要添加的基本信息 \

JButton addbtn=new JButton(\"添加\"); addframe.add(title,BorderLayout.NORTH); addframe.add(basebox,BorderLayout.CENTER); addframe.add(addbtn,BorderLayout.SOUTH); addbtn.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent event) {

Connection con; Statement st; ResultSet rs;

sno=notext.getText(); sname=nametext.getText(); sage=agetext.getText(); ssex=sextext.getText();

saddress=addresstext.getText(); sphone=phonetext.getText(); try {

Class.forName(\"sun.jdbc.odbc.JdbcOdbcDriver\"); }

catch(ClassNotFoundException e) {

System.out.println(e); }

try {

con=DriverManager.getConnection(\"jdbc:odbc:pan\;

st=con.createStatement();

int ok= st.executeUpdate(\"INSERT INTO student

VALUES(\"+\"'\"+sno+\"'\"+\\"+\+\"'\"+\")\");

if(ok==1) {

JOptionPane b=new JOptionPane(); b.showMessageDialog(null,\"添加成功\" ,\"消息对话框\ }

rs=st.executeQuery(\"SELECT student\");

while(rs.next()) {

String no=rs.getString(1);

*

FROM

String name=rs.getString(2); String age=rs.getString(3); String sex=rs.getString(4); String address=rs.getString(5); String phone=rs.getString(6); System.out.println(no+\" \"+

\"+age+\" \"+sex+\" \"+address+\" \"+phone); }

con.close(); }

catch(SQLException e) {

System.out.println(e); } } }); } }

name+\"

class AddUser {

void AddUser() {

final JFrame addframe=new JFrame(\"添加用户的界面\"); addframe.setBounds(200,200,400,500); addframe.setVisible(true); addframe.setResizable(true); addframe.setLayout(null);

final JTextField text1=new JTextField(15);

final JPasswordField text2=new JPasswordField(15);

JButton btn1=new JButton(\"确认\"); JButton btn2=new JButton(\"取消\"); JLabel

label1=new

JLabel(\"

\ JLabel

label2=new

JLabel(\"

\ addframe.add(btn1); addframe.add(btn2); addframe.add(text1); addframe.add(text2); addframe.add(label1); addframe.add(label2);

label1.setBounds(80, 100, 150, 50); label2.setBounds(80, 200, 150, 50); btn1.setForeground(Color.black); btn2.setForeground(Color.black); text1.setBounds(150, 100, 200, 30); text2.setBounds(150, 200, 200, 30); btn1.setBounds(100, 300, 100, 60); btn2.setBounds(200, 300, 100, 60);

btn1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent event) {

String name=text1.getText(); String password=text2.getText(); try {

Class.forName(\"sun.jdbc.odbc.JdbcOdbcDriver\"); }

catch(ClassNotFoundException e) {

System.out.println(\"\" + e); } try {

Connection con; Statement sql;

ResultSet rs;

con=DriverManager.getConnection(\"jdbc:odbc:pan\;

sql=con.createStatement();

int ok=sql.executeUpdate(\"INSERT INTO users VALUES('\"+name+\"',\"+\"'\"+password+\"')\"); if(ok==1)

{JOptionPane b=new JOptionPane(); b.showMessageDialog(null,\"添加成功\" ,\"消息对话框\ addframe.dispose(); } else {

JOptionPane b=new JOptionPane(); b.showMessageDialog(null,\"该用户已经存在\" ,\"消息对话框\ text1.setText(\"\"); text2.setText(\"\"); } }

catch(SQLException e) {

System.out.println(e); }

} });

btn2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent event) {

addframe.dispose(); } });

} }

class DeleteUser {

void DeleteUser() {

final JFrame deleteframe=new JFrame(\"删除用户\"); deleteframe.setLayout(null);

JLabel label=new JLabel(\"请输入要删除用户的账号\

deleteframe.setVisible(true);

deleteframe.setBounds(300,300,400,300); JButton btn=new JButton(\"确定\"); deleteframe.add(label);

label.setForeground(Color.black);

final JTextField text=new JTextField(15); text.setSize(100,60); deleteframe.add(text); deleteframe.add(btn);

label.setBounds(150, 50, 150, 20); text.setBounds(150, 100, 100, 20); btn.setBounds(150, 150, 100, 20);

btn.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent event) {

Connection con; Statement st; ResultSet rs;

String username=text.getText();

try {

Class.forName(\"sun.jdbc.odbc.JdbcOdbcDriver\"); }

catch(ClassNotFoundException e) {

System.out.println(e); } try {

con=DriverManager.getConnection(\"jdbc:odbc:pan\;

st=con.createStatement();

int ok= st.executeUpdate(\"DELETE FROM users WHERE username='\"+username+\"'\"); if(ok==1) {

JOptionPane b=new JOptionPane(); b.showMessageDialog(null,\"删除成功\" ,\"

消息对话框\ deleteframe.dispose(); } else {

JOptionPane b=new JOptionPane(); b.showMessageDialog(null,\"所要删除的用户

\"

,\"

\ }

con.close(); }

catch(SQLException e) {

System.out.println(e); } } }); } }

class AlterUser {

void AlterUser() {

final JFrame addframe=new JFrame(\"更改用户\"); final JFrame alterframe=new JFrame(\"修改页面\"); alterframe.setBounds(200,200,400,500); addframe.setBounds(200,200,400,500); addframe.setVisible(true); addframe.setResizable(true); alterframe.setResizable(true); addframe.setLayout(null); alterframe.setLayout(null);

final JTextField text1=new JTextField(15);

final JPasswordField text2=new JPasswordField(15); final JTextField text3=new JTextField(15);

final JPasswordField text4=new JPasswordField(15); JButton btn1=new JButton(\"确认\"); JButton btn3=new JButton(\"确认\"); JButton btn2=new JButton(\"取消\"); JButton btn4=new JButton(\"取消\");

JLabel label1=new JLabel(\"您现在的用户名 \

JLabel label3=new JLabel(\"您将要使用的用户名\

JLabel label2=new JLabel(\"密码\ JLabel label4=new JLabel(\"密码\ addframe.add(btn1); addframe.add(btn2); alterframe.add(btn3); alterframe.add(btn4); addframe.add(text1); addframe.add(text2); alterframe.add(text3); alterframe.add(text4); addframe.add(label1);

alterframe.add(label3); alterframe.add(label4); addframe.add(label2);

label1.setBounds(80, 100, 150, 50); label2.setBounds(80, 200, 150, 50); label3.setBounds(30, 100, 150, 50); label4.setBounds(30, 200, 150, 50); btn1.setForeground(Color.black); btn2.setForeground(Color.black); btn3.setForeground(Color.black); btn4.setForeground(Color.black); text1.setBounds(160, 100, 200, 30); text2.setBounds(160, 200, 200, 30); text3.setBounds(160, 100, 200, 30); text4.setBounds(160, 200, 200, 30); btn1.setBounds(100, 300, 100, 60); btn2.setBounds(200, 300, 100, 60); btn3.setBounds(100, 300, 100, 60); btn4.setBounds(200, 300, 100, 60);

btn1.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent event) {

String name=text1.getText(); String password=text2.getText(); try {

Class.forName(\"sun.jdbc.odbc.JdbcOdbcDriver\"); }

catch(ClassNotFoundException e) {

System.out.println(\"\" + e); } try {

Connection con,con1; Statement sql,st; ResultSet rs;

con=DriverManager.getConnection(\"jdbc:odbc:pan\;

con1=DriverManager.getConnection(\"jdbc:odbc:pan\);

sql=con.createStatement(); st=con1.createStatement();

rs= sql.executeQuery(\"SELECT * FROM users WHERE username='\"+name+\"' AND password='\"+password+\"'\"); if(rs.next()) {

JOptionPane b=new JOptionPane(); b.showMessageDialog(null,\"请填写您要修改的信息\" ,\"消息对话框\ addframe.dispose();

alterframe.setVisible(true); } else {

JOptionPane b=new JOptionPane(); b.showMessageDialog(null,\"对不起,该用户

\"

,\"

\ text1.setText(\"\"); text2.setText(\"\"); } }

catch(SQLException e) {

System.out.println(e); }

} });

btn2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent event)

{

addframe.dispose(); } });

btn3.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent event) {

String name1=text3.getText(); String password1=text4.getText(); try {

Class.forName(\"sun.jdbc.odbc.JdbcOdbcDriver\"); }

catch(ClassNotFoundException e) {

System.out.println(\"\" + e); } try {

Connection con; Statement sql; ResultSet rs;

con=DriverManager.getConnection(\"jdbc:odbc:pan\;

sql=con.createStatement();

int ok=sql.executeUpdate(\"INSERT INTO users VALUES('\"+name1+\"','\"+password1+\"')\"); if(ok==1) {

JOptionPane b=new JOptionPane(); b.showMessageDialog(null,\"修改成功\" ,\"消息对话框\ }

con.close(); }

catch(SQLException e)

{

System.out.println(e); } } });

btn4.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent event) {

alterframe.dispose(); } }); } }

class AlterPword {String name; void AlterPword() {

final JFrame addframe=new JFrame(\"修改密码\"); final JFrame alterframe=new JFrame(\"修改页面\"); alterframe.setBounds(200,200,400,500); addframe.setBounds(200,200,400,500); addframe.setVisible(true); addframe.setResizable(true);

alterframe.setResizable(true); addframe.setLayout(null); alterframe.setLayout(null);

final JTextField text1=new JTextField(15);

final JPasswordField text2=new JPasswordField(15); final JPasswordField text3=new JPasswordField(15); final JPasswordField text4=new JPasswordField(15); JButton btn1=new JButton(\"确认\"); JButton btn3=new JButton(\"确认\"); JButton btn2=new JButton(\"取消\"); JButton btn4=new JButton(\"取消\");

JLabel label1=new JLabel(\"您现在的用户名 \

JLabel label3=new JLabel(\"请输入新密码\ JLabel label2=new JLabel(\"密码\ JLabel label4=new JLabel(\"请再输入一次新密码\ addframe.add(btn1); addframe.add(btn2); alterframe.add(btn3); alterframe.add(btn4); addframe.add(text1);

addframe.add(text2); alterframe.add(text3); alterframe.add(text4); addframe.add(label1); alterframe.add(label3); alterframe.add(label4); addframe.add(label2);

label1.setBounds(80, 100, 150, 50); label2.setBounds(80, 200, 150, 50); label3.setBounds(30, 100, 150, 50); label4.setBounds(30, 200, 150, 50); btn1.setForeground(Color.red); btn2.setForeground(Color.red); btn3.setForeground(Color.red); btn4.setForeground(Color.red); text1.setBounds(160, 100, 200, 30); text2.setBounds(160, 200, 200, 30); text3.setBounds(160, 100, 200, 30); text4.setBounds(160, 200, 200, 30); btn1.setBounds(100, 300, 100, 60); btn2.setBounds(200, 300, 100, 60); btn3.setBounds(100, 300, 100, 60);

btn4.setBounds(200, 300, 100, 60);

btn1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent event) {

name=text1.getText(); String password=text2.getText(); try {

Class.forName(\"sun.jdbc.odbc.JdbcOdbcDriver\"); }

catch(ClassNotFoundException e) {

System.out.println(\"\" + e); } try

{

Connection con,con1; Statement sql,st; ResultSet rs;

con=DriverManager.getConnection(\"jdbc:odbc:pan\;

con1=DriverManager.getConnection(\"jdbc:odbc:pan\);

sql=con.createStatement(); st=con1.createStatement();

rs= sql.executeQuery(\"SELECT password FROM users WHERE username='\"+name+\"'\");

JOptionPane b=new JOptionPane(); b.showMessageDialog(null,\"请填写您要修改的密码\" ,\"消息对话框\ addframe.dispose();

alterframe.setVisible(true); }

catch(SQLException e) {

System.out.println(e); }

} });

btn2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent event) {

addframe.dispose(); }

});

btn3.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent event) {

String password2=text3.getText(); String password1=text4.getText(); try {

Class.forName(\"sun.jdbc.odbc.JdbcOdbcDriver\"); }

catch(ClassNotFoundException e) {

System.out.println(\"\" + e); } try {

Connection con;

Statement sql; ResultSet rs;

con=DriverManager.getConnection(\"jdbc:odbc:pan\;

sql=con.createStatement();

int ok=sql.executeUpdate(\"update users set

password='\"+password1+\"'\"+\"where

username='\"+name+\"'\"); if(ok==1) {

JOptionPane b=new JOptionPane(); b.showMessageDialog(null,\"修改成功\" ,\"消息对话框\ }

con.close(); }

catch(SQLException e) {

System.out.println(e); }

} });

btn4.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent event) {

addframe.dispose(); } }); } }

class SystemHelp {

void SystemHelp() {

JFrame frame1=new JFrame(\"帮助窗体\"); frame1.setLayout(new BorderLayout()); JTextField text=new JTextField(); text.setEditable(false); text.setAlignmentX(1);

frame1.setBounds(200,200,200,200);

frame1.setVisible(true);

frame1.setResizable(true);

frame1.add(text,BorderLayout.CENTER);

String str1=new String(\" 不同用户的权限不同\");

text.setText(str1); } }

class SystemExit {

void SystemExit() {

System.exit(0); } }

2、调试分析及实验心得

本次JAVA实习作业,是我第一次完成一个较为具体、复杂、完整的程序。这对我来说是一个巨大的挑战。 本次操作增强了我编程的思维能力和操作能力。也提高了我分析问题和解决问题的能力。

首先,在调试程序时,我经常在调用ACCESS数据库上出问题,比如我只想删除用户的密码,但程序执行的结果却是把用户的所有信息都删除了。经过不断的调试,我发现自己的语句出了问题,我翻阅数本,上网查找资料后,加以修改。再执行,就成功了。

其次是代码处理水平的一个升级。原来我写程序,就是在脑子里有一个大概,就开始写。而这次,我是先在白纸上列了一个顺序,然后开始一条条编写的。我觉得这样更加有条理性,更加清晰,明确。

最后,我觉得编程是一个需要细心与耐心的过程。很多时候,就是一个标点符号的错误,或者是字母大小写的问题就会导致整个程序的错误。这个时候,不能着急,要沉下心,找到出问题的地方,然后一点点往回找。

总之,在编写、调试整个程序中,我学到了许多,我有信心去迎接新的挑战!

3、实验总结

JAVA是一门优秀的编程语言,具有面向对象,与平台

无关,安全、稳定和多线程等特点,是目前软件设计中极为健全的语言。

经过一学期的JAVA学习,对JAVA编程有了一定的认识,在做这个程序设计的时期,刚开始感觉自己无从下手,不知道该怎么开始,很茫然。之后我查阅各种资料,无论是书本上的,还是网上的,只要是我认为有价值的,我都认真看,分析。接着,我就在一张白纸上列出了自己的思路。终于在两周的时间内完成了学生信息管理系统这一项目。当程序运行结果看到自己所想达的要求界面时感到很欣慰,虽然只是一个小的项目,但是却是自己第一次完成的一个完整项目,我也从中学到了很多书本知识不能体现的东西,对JAVA也有了更深一步的认识与了解。

通过这次的程序设计,我发现自己平时对于编程实际操作的匮乏,没有把书本上的知识真正的掌握牢固,仍然有许多的问题考虑不全面。我相信,在今后的编程道路上,我一定会更加仔细认真,积累经验,成为一名合格的程序员。

因篇幅问题不能全部显示,请点此查看更多更全内容