}
}
}
5.3 java程序实现
GetConnection.java 连接数据库类 Login 主类,main函数 Login_win 登录界面类 xuanke 选课类 shake 删课类
StudentFrame 学生信息类 Teacher 查看教师信息类
注意:程序类的具体代码实现见附页
6. 系统的使用说明及环境配置
学生选课系统提供了学生选课系统。学生通过以自己的学号(如10001)作为用户名和自定义的密码注册、登录系统后进行相应的学生权限范围内的操作。
连接数据库的登录名:root 密码:root.
附录
相关程序代码如下: 1、数据连接: import java.sql.*; import java.awt.*;
import java.awt.event.*;
import javax.swing.Box;
class GetConnection { private static String driver=\ private static String url=\ private static String user=\ private static String password=\ public static Connection getConnection(){ try{ Class.forName(driver); Connection conn=DriverManager.getConnection(url, user, password); return conn; } catch(Exception e){ e.printStackTrace(); return null; } } }
2、登录:
import java.awt.*;
import java.awt.event.*; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.*;
import javax.swing.border.*; // 该包中提供Box类
public class Login { public static void main(String args[]){ DengLu_JieMian jiemian=new DengLu_JieMian(); } }
//登录界面,使用BoxLayout布局
class DengLu_JieMian extends Frame implements ActionListener { Button button1,button2; TextField text1,text2; String code=null; DengLu_JieMian(){ setTitle(\欢迎进入湘潭大学选课系统\ Box baseBox,boxV1,boxV2,boxV3,boxV4; boxV1=Box.createHorizontalBox(); Label label1=new Label(\选 课 系 统\ //改变label标签中的字体 label1.setFont(new Font(\ boxV1.add(Box.createHorizontalStrut(25)); boxV1.add(label1); boxV2=Box.createHorizontalBox(); boxV2.add(new Label(\学号\ //两个组件之间添加水平距离 boxV2.add(Box.createHorizontalStrut(10)); text1=new TextField(15); boxV2.add(text1); boxV3=Box.createHorizontalBox(); boxV3.add(new Label(\密码\ boxV3.add(Box.createHorizontalStrut(10)); text2=new TextField(15); text2.setEchoChar('*'); boxV3.add(text2); boxV4=Box.createHorizontalBox(); button1=new Button(\登录\ button1.addActionListener(this); button2=new Button(\退出\ button2.addActionListener(this);
boxV4.add(button1); boxV4.add(Box.createHorizontalStrut(3)); boxV4.add(button2); baseBox=Box.createVerticalBox(); baseBox.add(boxV1); baseBox.add(Box.createVerticalStrut(8)); baseBox.add(boxV2); baseBox.add(Box.createVerticalStrut(8)); baseBox.add(boxV3); baseBox.add(Box.createVerticalStrut(8)); baseBox.add(boxV4); addWindowListener(new WindowAdapter() {// 关闭程序时的操作 public void windowClosing(WindowEvent e) { System.exit(0); } }); setLayout(new FlowLayout()); add(baseBox); setBounds(500,300,500,300); setVisible(true); } public void actionPerformed(ActionEvent e) { if(e.getSource()==button1){ if(text1.getText().equals(\ JOptionPane.showMessageDialog(this,\用户名不能不为空\ } else if(text2.getText().equals(\ JOptionPane.showMessageDialog(null, \密码不能为空,请重新填写\ } if(!(text1.getText().equals(\ try{ Connection conn=GetConnection.getConnection(); PreparedStatement sql2=conn.prepareStatement(\DISTINCT password FROM user WHERE s_id=\ ResultSet rs2=sql2.executeQuery(); while(rs2.next()){ code=rs2.getString(1); } } catch(SQLException e1){
System.out.println(e1); } if(text2.getText().equals(code)){ new StudentFrame(text1.getText()); JOptionPane.showMessageDialog(this,\登录成功\ dispose(); } else{ JOptionPane.showMessageDialog(this,\登录失败\ } } } else if(e.getSource()==button2){ //离开程序 System.exit(0); } } }
3、删课:
import java.awt.*;
import java.awt.event.*; import java.sql.*;
import javax.swing.Box;
class shanke extends Frame { Label xuehao,xingming; Checkbox checkbox2[]; Label l1[],l2[],l3[]; Panel panel; Button b1; shanke(String s1,String s2){ super(\删课界面\ xuehao=new Label(s1); xingming=new Label(s2); Panel p1=new Panel(); p1.add(new Label(\学号:\ p1.add(xuehao); p1.add(new Label(\姓名:\ p1.add(xingming); p1.add(new Label(\欢迎进入选课界面\
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库数据库实验报告(7)在线全文阅读。
相关推荐: