有些同学跟我要代码但是因为我没及时看到所以没能及时回复,很抱歉!于是把代码放到github里了。https://github.com/DKAngel/DatabaseExperiment

这次所要介绍的内容是数据库课设做的东西。利用数据库SQL server 2008与Java设计实现学生学籍管理系统,分为几次步骤来介绍。第一次介绍准备、登录界面的设计,第二次介绍注册、学籍管理等界面的设计,第三次介绍相关查询、统计等的设计。

首先是配置Java连接SQL的环境

过程不是很复杂,网上都有教程,跟着做就可以了,这里不在累述。

其次是Java连接SQL的方法

  提醒一下连接数据库需要打开SQL Server(MSSQLSERVER)服务。
    String account;//账号,代码中通过输入获取String password;//密码,代码中通过输入获取String connectDB = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=Databaseproject";//数据源DatabaseName是你建的数据库Connection con;                          //连接数据库对象Statement stmt;                            //创建SQL命令对象String JDriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";  //SQL数据库引擎try {Class.forName(JDriver);con = DriverManager.getConnection(connectDB, account, password);stmt = con.createStatement();JOptionPane.showMessageDialog(null,"数据库驱动成功");} catch (ClassNotFoundException e) {JOptionPane.showMessageDialog(null,"加载数据库引擎失败");}

总体设计

  学生管理系统需要的功能有:管理员登录(Main)、用户注册(Register)、切换用户、注销、功能选择(Choice):学生档案管理(Record_Manage)、学生学籍管理(School_Manage)、学生成绩管理(Score_Manage)、统计查询(Statistics_Manage)。

登录界面的设计与实现

  界面要做的美观大方有特色,我所设计界面的说不上美观,但还算可以。主要的思想是:用户未连接之前显示账号、密码框,供用户登录使用;用户登录成功后显示“welcome用户名”的样式。将登录控件放在JPanel上,判断是否登录,登录成功后,将JPanel上的内容removeAll再将welcome用户名添加到JPanel上,以此来实现刷新界面的效果。账号输入框用FocusListener实现了动态显示“输入账号”的功能。代码如下:
package Main;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import Graphical_User_Interface.Choice;
import Graphical_User_Interface.Register;
public class Main extends JFrame implements ActionListener,FocusListener{String account;String password;String connectDB = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=Databaseproject";//数据源Connection con;                          //连接数据库对象Statement stmt;                            //创建SQL命令对象boolean flag = false;                   //标识是否登录    Font font0 = new Font("楷体_GB2312",Font.BOLD+Font.ITALIC,40);        //Font:字体类型Font font = new Font("楷体_GB2312",Font.BOLD+Font.ITALIC,25);   Font font1 = new Font("楷体_GB2312",Font.BOLD+Font.ITALIC,20);String str = "输入账号"; String path = "C:/Users/yangcheng/workspace/DatabaseExperiment/src"     //背景图片绝对路径+ "/Graphical_User_Interface/背景.png";String path1 = "C:/Users/yangcheng/workspace/DatabaseExperiment/src"    //登录按钮+ "/Graphical_User_Interface/登录.png";String path2 = "C:/Users/yangcheng/workspace/DatabaseExperiment/src/Graphical_User_Interface/注销.png";String path3 = "C:/Users/yangcheng/workspace/DatabaseExperiment/src/Graphical_User_Interface/注册.png";String path4 = "C:/Users/yangcheng/workspace/DatabaseExperiment/src/Graphical_User_Interface/功能选择.png";String path5 = "C:/Users/yangcheng/workspace/DatabaseExperiment/src/Graphical_User_Interface/切换用户.png";JButton JB_log_in = new JButton("");JButton JB_log_out = new JButton("");JButton JB_change = new JButton("");JButton JB_register = new JButton("");JButton JB_choice = new JButton("");    JTextField login_act = new JTextField("输入账号");JPasswordField login_pwd;JPanel jp = new JPanel();//*******************************************************************************public Main(){this.setTitle("学籍管理系统");this.setSize(500,500);this.setLayout(new GridLayout(3,4,10,10));  //网格布局this.setLocationRelativeTo(null);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       ImageIcon bg = new ImageIcon(path);                        //背景图片JLabel label = new JLabel(bg);label.setBounds(0,0,bg.getIconWidth(),bg.getIconHeight());this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));JPanel imgP = (JPanel)this.getContentPane();imgP.setOpaque(false);     String JDriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";// SQL数据库引擎        try {Class.forName(JDriver);JOptionPane.showMessageDialog(null,"数据库驱动成功");} catch (ClassNotFoundException e) {JOptionPane.showMessageDialog(null,"加载数据库引擎失败");}   this.add(createN());this.add(createC());this.add(createS());        this.setVisible(true);this.setResizable(false);}
//*******************************************************************************public JPanel createN(){JPanel jpl = new JPanel();jpl.setLayout(new FlowLayout(FlowLayout.CENTER,33,20));     String tit = "   学籍管理系统";JLabel lb0 = new JLabel(tit);                           //标题lb0.setFont(font0);jpl.add(lb0);       String by = "   By:Dkangel";JLabel lb3 = new JLabel(by);                             //bylb3.setFont(font);jpl.add(lb3);        jpl.setOpaque(false);return jpl;}
//*******************************************************************************public JPanel createC(){jp.setLayout(new FlowLayout(FlowLayout.CENTER,30,20));     JLabel lb1 = new JLabel("账号:");                          //账号框lb1.setFont(font);login_act = new JTextField(str,15);login_act.setFont(font1);login_act.addFocusListener(this);jp.add(lb1);jp.add(login_act);      JLabel lb2 = new JLabel("密码:");                          //密码框lb2.setFont(font);login_pwd = new JPasswordField(15);login_pwd.setFont(font1);jp.add(lb2);jp.add(login_pwd);       jp.setOpaque(false);return jp;}
//*******************************************************************************   public JPanel createS(){JPanel jpl = new JPanel();jpl.setLayout(new FlowLayout(FlowLayout.CENTER,30,10));ImageIcon image_login = new ImageIcon(path1);             //登录按钮JB_log_in.setIcon(image_login);JB_log_in.setBorderPainted(false);JB_log_in.setActionCommand("login");JB_log_in.addActionListener(this);JB_log_in.setPreferredSize(new Dimension(40,40));jpl.add(JB_log_in);ImageIcon image_choice = new ImageIcon(path4);            //功能选择按钮JB_choice.setIcon(image_choice);JB_choice.setBorderPainted(false);JB_choice.setActionCommand("logchoice");JB_choice.addActionListener(this);JB_choice.setPreferredSize(new Dimension(40,40));jpl.add(JB_choice);ImageIcon image_change = new ImageIcon(path5);            //切换用户按钮JB_change.setIcon(image_change);JB_change.setBorderPainted(false);JB_change.setActionCommand("logchange");JB_change.addActionListener(this);JB_change.setPreferredSize(new Dimension(40,40));  jpl.add(JB_change);JButton jbt = new JButton();                 //利用空Button实现换行的效果jbt.setPreferredSize(new Dimension(500,10));  jbt.setBorderPainted(false);jbt.setContentAreaFilled(false);jpl.add(jbt);ImageIcon image_register = new ImageIcon(path3);           //注册按钮JB_register.setIcon(image_register);JB_register.setBorderPainted(false);JB_register.setActionCommand("register");JB_register.addActionListener(this);JB_register.setPreferredSize(new Dimension(40,40));  jpl.add(JB_register);ImageIcon image_logout = new ImageIcon(path2);             //注销按钮JB_log_out.setIcon(image_logout);JB_log_out.setBorderPainted(false);JB_log_out.setActionCommand("logout");JB_log_out.addActionListener(this);JB_log_out.setPreferredSize(new Dimension(45,45));  jpl.add(JB_log_out);jpl.setOpaque(false);return jpl;}
//*******************************************************************************   public void focusGained(FocusEvent arg0){                      //动态实现输入账号String content = login_act.getText();if(content.equals("输入账号")){login_act.setText("");}else{login_act.setText(content);}} public void focusLost(FocusEvent arg0){String content = login_act.getText();if(!content.equals("输入账号") && content.equals("")){login_act.setText(str);}else{login_act.setText(content);}}
//*******************************************************************************   public void actionPerformed(ActionEvent e){if(e.getActionCommand().equals("login") && !flag){                   //登录操作account = login_act.getText();char[] pwd = login_pwd.getPassword();           password = new String(pwd);if(!account.equals("输入账号") && !account.equals("")){try {con = DriverManager.getConnection(connectDB, account, password);                   if(con != null){JOptionPane.showMessageDialog(null,"登录成功");flag = true;jp.removeAll();jp.repaint();stmt = con.createStatement();                   ResultSet rs = stmt.executeQuery("select * from My_Adminstrator"); //My_Adminstrator结果集                  while (rs.next()) {if(rs.getString("Account").equals(account)){jp = Display(rs.getString("NAME"));break;}}this.add(jp);this.validate();}} catch (Exception e1) {JOptionPane.showMessageDialog(null,"数据库连接失败");}}else{JOptionPane.showMessageDialog(null,"账号或密码不能为空!!!");}}if(e.getActionCommand().equals("logchoice")){                  //选择功能操作         if(flag){new Choice(account,password);}else{JOptionPane.showMessageDialog(null,"还未登录");}}if(e.getActionCommand().equals("logchange")){                 //切换用户操作     if(flag){try{stmt.close();con.close();flag = false;JOptionPane.showMessageDialog(null,"切换用户成功");                    jp.removeAll();jp.repaint();jp = createC();this.add(jp);this.validate();}catch(Exception ex){}}else{JOptionPane.showMessageDialog(null,"还未登录");}}if(e.getActionCommand().equals("register")){                    //注册if(flag){new Register(account,password);}else{JOptionPane.showMessageDialog(null,"还未登录");}}if(e.getActionCommand().equals("logout")){                     //退出try {if(flag){stmt.close();con.close();}dispose();System.exit(0);} catch (SQLException e1) {}}}public JPanel Display(String str){jp.setLayout(new GridLayout(2,1,1,5));     String tit = "           W e l c o m e";JLabel lb0 = new JLabel(tit);                    lb0.setFont(font0);jp.add(lb0);        JLabel lb3 = new JLabel("                       name:" + str);                    lb3.setFont(font);jp.add(lb3);     jp.setOpaque(false);return jp;}public static void main(String[] args){new Main();}
}

过程演示:

数据库加载成功则会出现该消息框。
未登录前的主界面。
登录后界面刷新,显示Welcome name:名称。

学生学籍管理系统~~登录界面(Java、SQL)相关推荐

  1. 学生学籍管理系统~~功能界面

    之前介绍了登录界面的设计,现在介绍一下注册管理员和录入信息的部分. 设计注册管理员的思想是:默认一个拥有创建用户的管理员,这个管理员可以创建数据库登录用户(相当于创建教师),而这些用户只能登录和进行其 ...

  2. 【计算机毕业设计】679学生学籍管理系统

    一.系统截图(需要演示视频可以私聊) 目 录 目 录 摘  要 ABSTRACT 1 绪论 1.1 课题背景 1.2 研究现状 1.3 研究内容 2 系统开发环境 2.1 vue技术 2.2 JAVA ...

  3. 【学生系统】——登录界面

    登录窗体可谓是一个系统的门面,这个门面的简洁程度.为人民服务的程度以及易操作程度将直接影响用户对这个系统的喜爱程度,也就是说第一眼很大程度的决定了用户是否选择你的系统. 关于学生信息管理系统登录界面其 ...

  4. 基于java的学生学籍管理系统(含源文件)

    欢迎添加微信互相交流学习哦! 项目源码:https://gitee.com/oklongmm/biye 目录 内容摘要    - 2 - 引言    - 4 - 学生学籍管理系统开发的意义和目的   ...

  5. [内附完整源码和文档] 基于Java的学生学籍管理系统

    摘 要 学生学籍管理系统是一个教育单位不可缺少的重要部分之一,学生学籍内容对学校的管理者和决策者来说都是至关重要的,而传统的学籍管理方式十分的复杂繁琐.低效率,在计算机普及的现代,开发一个高效简便学生 ...

  6. C语言编程学生学籍登录窗口,C语言实现学生学籍管理系统

    本文实例为大家分享了C语言实现学生学籍管理系统的具体代码,供大家参考,具体内容如下 #include #include #include #include #include //*********** ...

  7. java学籍管理系统 课程设计,Java课程设计---学生学籍管理系统

    Java课程设计---学生学籍管理系统 设计报告设计报告 课题名称学生学籍管理系统 学院 专业班级计算机应用技术 091 学号 学生 指导教师 2011 年 7 月 7 日 1 学生 指导教师 课题名 ...

  8. C语言学生学籍管理系统源程序|用数据文件存放学生的学籍,可对学生学籍进行注册,登录,修改,删除,查找,统计,学籍变化等操作。(用文件保存) 功能要求: (1) 系统以菜单方式工作。 (2) 登记学生的

    学生学籍管理系统 用数据文件存放学生的学籍,可对学生学籍进行注册,登录,修改,删除,查找,统计,学籍变化等操作.(用文件保存) 功能要求: (1) 系统以菜单方式工作. (2) 登记学生的学号,姓名, ...

  9. 学生学籍管理系统,vs2010+sql server2008 及以上版本完美运行

    学生学籍管理系统,vs2010+sql server2008 及以上版本完美运行 学生学籍管理系统,vs2010+sql server2008 及以上版本完美运行

最新文章

  1. C语言结构体自动初始化实现,C语言中结构体(struct)的几种初始化方法
  2. iOS UIWebView 访问https 绕过证书验证的方法
  3. 简单的问题和复杂的问题
  4. Hibernate之HQL数据库操作
  5. HTML的input类型为hidden导致无法reset改字段的value问题
  6. DataWorks功能实践速览 — 参数透传
  7. Udemy - Build Apps with React Native
  8. python一行代码打印Love心形
  9. CF1408D:Searchlights
  10. 软件设计原则及设计模式
  11. python-day19-面向对象进阶-加载顺序,命名空间,组合(实现松耦合)
  12. 关于TP遇到的问题点和解决办法
  13. matplotlib plot 分组_Python数据分析模块二:Matplotlib
  14. 禅道客户端安装教程(超详细)
  15. 联想G480黑苹果安装成功
  16. Context-Aware Patch Generation for Better Automated Program Repair -上下文感知补丁生成更好的自动化程序修复
  17. RFID仓库管理系统解决方案有哪些功能模块
  18. HBuilder X 连接苹果手机(IOS)详细教程。Windows: 连接iOS手机调试项目
  19. 太原理工大于丹计算机,太原理工大学硕士生将参加中国第30次南极考察
  20. Windows DNS服务器的子网掩码排序

热门文章

  1. qt 频谱 音乐播放器
  2. 《全球通史》读书笔记2
  3. ubuntu系统外连接两个显示器设置
  4. 练习-CTF解题 - XMAN比赛 8-8-babyweb(netspark扫扫)
  5. python字典统计单词个数_python字典统计单词个数
  6. 单模、多模有什么区别
  7. 使用计算机生成遐想景物图像,计算机多媒体
  8. 常见神经系统疾病的临床诊断及处理原则题库【2】
  9. 9小时突破1000亿,你以为这就是阿里双十一的最大胜利?
  10. 抖音算法推荐机制详解