学校管理系统源码.docx
- 文档编号:7928330
- 上传时间:2023-01-27
- 格式:DOCX
- 页数:95
- 大小:44.61KB
学校管理系统源码.docx
《学校管理系统源码.docx》由会员分享,可在线阅读,更多相关《学校管理系统源码.docx(95页珍藏版)》请在冰豆网上搜索。
学校管理系统源码
packagemain;
importjavax.swing.*;
importjava.awt.event.*;
importjava.sql.*;
importclib.*;
importsetwindow.*;
importmysystem.*;
importuser.*;
publicclassSchoolMain
{
privateSchoolMain(){
//创建登录界面
(newDengLuSet().getAdminLogin()).setVisible(true);
}
publicstaticvoidmain(String[]args){
////////////////读取配置文件/////////////////
Stringconnect=ConfigClass.getValue("lianjie");
try{
//连接数据库
if(connect.equals("JDBC")){//JDBC连接
DBClass.lianJieJDBC();
}elseif(connect.equals("ODBC")){//ODBC连接
DBClass.lianJieODBC();
}
newSchoolMain();
}catch(Exceptionex){
ex.printStackTrace();
}
}
}
packageuser;
importjavax.swing.*;
importjava.awt.event.*;
importjava.sql.*;
importclib.*;
importsetwindow.*;
importmysystem.*;
importuser.*;
/**
*================================================
*登录设置类实现
*时间:
2010-04-26
*================================================
*/
publicclassDengLuSetextendsJFrame
implementsActionListener,FocusListener,KeyListener{
//四个按钮,依次为确定,取消,重填,帮助
privateJButtonloginButtons=null;
//登录界面
privateAdminLoginadminLogin=null;
//用户文本框焦点监听时需要
privateJTextFieldtfName=null;
privateJPasswordFieldpfPass=null;
privateintcount=0;
/**
*设置风格
*/
publicDengLuSet(){
CsUIManager.setUI(this,CsUIManager.BOLD);
//设置外观颜色
newUIColorChooser(this).changeUIColor();
//初始化登录界面
adminLogin=newAdminLogin();
adminLogin.addButtonListener(this);
tfName=adminLogin.getNameField();
pfPass=adminLogin.getPasswordField();
tfName.addFocusListener(this);
loginButtons=adminLogin.getSubmitButton();
loginButtons.addKeyListener(this);
adminLogin.setVisible(true);
}
/**
*返回登录窗口
*/
publicAdminLogingetAdminLogin(){
returnadminLogin;
}
/**
*判断用户
*
*@returnint返回权限代号,如果失败,返回-1
*/
privateintcheckUser()throwsException{
//获得用户名
StringuserName=adminLogin.getUserName();
//获得密码
Stringpassword=adminLogin.getPassword();
//获得权限下
ResultSetrs=DBClass.chuLiSqlA("selectmima,quanxianfromusertablewherename='"
+userName+"'");
if(rs.next()){
Stringpass=rs.getString
(1);
//密码正确
if(pass.equals(password)){
StringquanXian=rs.getString
(2);
Stringindex=adminLogin.getSelectedListValue();
//普通用户权限判断
if(index.equals("")){
return-1;
//存在(进入系统)
}else{
returnInteger.parseInt(quanXian);
}
}else{
return-2;
}
//无用户
}else{
JOptionPane.showMessageDialog(null,"没有你输入的用户,请检查");
}
return-1;
}
/**
*MethodfocusGained
*/
publicvoidfocusGained(FocusEvente){
}
/**
*MethodfocusLost
*/
publicvoidfocusLost(FocusEvente){
Objectsource=e.getSource();
try{
//用户名栏
if(source==tfName){
StringuserName=adminLogin.getUserName();
ResultSetrs=DBClass.chuLiSqlA("selectquanxianfromusertablewherename='"
+userName+"'");
if(rs.next()){
StringquanXian=rs.getString
(1);
if(quanXian.equals("0")){
adminLogin.setListData("普通用户");
}else{
adminLogin.setListData("管理员");
}
}else{
adminLogin.setListData(null);
}
}
}
catch(Exceptionex){
ex.printStackTrace();
}
}
publicvoidactionPerformed(ActionEventae){
Objectsource=ae.getSource();
try{
if(source==loginButtons){
//用户可以输入三次
intindex=this.checkUser();
if(index==1||index==0){
adminLogin.setVisible(false);
MainWindowmainWindow=newMainWindow(index);
mainWindow.setVisible(true);
return;
}elseif(index==-2){
count++;
if(count==3){
JOptionPane.showMessageDialog(null,"密码输入错误,退出本系统!
");
System.exit(0);//如果循环完了,就退出系统
}
JOptionPane.showMessageDialog(null,"密码输入错误,你还有"
+(3-count)+"次登录机会!
");
pfPass.requestFocus(true);
pfPass.setText("");
}
}
}
catch(Exceptionex){
ex.printStackTrace();
}
}
/**
*MethodkeyTyped
*/
publicvoidkeyTyped(KeyEvente){
Objectsource=e.getSource();
try{
if(source==loginButtons){
if(e.getKeyChar()==KeyEvent.VK_ENTER){
//用户可以输入三次
intindex=this.checkUser();
if(index==1||index==0){
adminLogin.setVisible(false);
MainWindowmainWindow=newMainWindow(index);
mainWindow.setVisible(true);
return;
}elseif(index==-2){
count++;
if(count==3){
JOptionPane.showMessageDialog(null,"密码输入错误,退出本系统!
");
System.exit(0);//如果循环完了,就退出系统
}
JOptionPane.showMessageDialog(null,"密码输入错误,你还有"
+(3-count)+"次登录机会!
");
pfPass.requestFocus(true);
pfPass.setText("");
}
}
}
}
catch(Exceptionex){
ex.printStackTrace();
}
}
publicvoidkeyPressed(KeyEvente){
}
publicvoidkeyReleased(KeyEvente){
}
}
登录类
/*
*@(#)AdminLogin.java2010-4-8
*
*publicclass
*/
packageuser;
importjavax.swing.*;
importjava.awt.*;
importjava.awt.event.*;
importclib.*;
/**
*AdminLogin
*
*说明:
本类为用户登录界面(对读取数据库信息和判断用户名密码正确与否,请自行监控)
*@version2006-4-811:
46:
17
*@seeCsSetup设置窗口居中方法
*@seeJButton自定义按钮类
*/
publicclassAdminLoginextendsJFrameimplementsMouseListener,ActionListener{
//待监听控件
privateJButtonbuttonSubmit,buttonCancel,buttonReset;//,buttonHelp;
privateJTextFieldtfName;
privateJPasswordFieldpfPass;
privateJLabellabelClew;
privateJListlistLevel;
privateFontfont=newFont("宋体",Font.PLAIN,12);
privateFontfontTitle=newFont("宋体",Font.BOLD,12);
private.URLurl=AdminLogin.class.getResource("/image/logo.gif");
privateImageIconlogoImageIcon=newImageIcon(url);
private.URLurl1=AdminLogin.class.getResource("/image/small/user.gif");
privateImagelogoIcon=newImageIcon(url1).getImage();
/**
*设置图片标志
*
*@paramimageIcon:
接受图片
*/
publicvoidsetLogoImageIcon(ImageIconimageIcon){
this.logoImageIcon=imageIcon;
}
/**
*设置标题栏图片
*
*@paramimage:
接受要设置的图片
*/
publicvoidsetLogoIcon(Imageimage){
this.logoIcon=image;
}
/**
*设置面板文字字体
*
*@paramtheFont:
接受要设置的字体
*/
publicvoidsetPaneFont(FonttheFont){
this.font=theFont;
}
/**
*设置标题字体
*
*@paramtheFont:
接受要设置的字体
*/
publicvoidsetTitleFont(FonttheFont){
this.fontTitle=theFont;
}
/**
*设置默认用户名
*
*@paramtext:
接受文本信息
*/
publicvoidsetUserName(Stringtext){
this.tfName.setText(text);
}
/**
*设置默认密码
*
*@parampass
*/
publicvoidsetPassWord(Stringpass){
this.pfPass.setText(pass);
}
/**
*设置级别信息
*
*@paramlevel:
接受级别文本信息
*/
publicvoidsetLevelList(String[]level){
this.listLevel.setListData(level);
listLevel.setSelectedIndex(0);
}
/**
*设置一个级别
*
*@paramlevel:
接受级别文本信息
*/
publicvoidsetListData(Stringlevel){
String[]lev={level};
this.listLevel.removeAll();
this.listLevel.setListData(lev);
if(level!
=null){
listLevel.setSelectedIndex(0);
}
}
/**
*返回列表框有无值
*/
/**
*设置按钮文本
*
*@paramtext:
接受4个字符串
*@return返回设置是否成功
*/
publicbooleansetButtonsText(String[]text){
intlength=text.length;
if(length!
=4){
returnfalse;
}
buttonSubmit.setText(text[0]);
buttonCancel.setText(text[1]);
buttonReset.setText(text[2]);
//buttonHelp.setText(text[3]);
returntrue;
}
/**
*返回用户名
*/
publicStringgetUserName(){
if(tfName.getText().equals("")){
returnnull;
}
returntfName.getText().trim();
}
/**
*返回密码
*/
publicStringgetPassword(){
char[]myPass=pfPass.getPassword();
returnString.valueOf(myPass);
}
/**
*返回权限下标
*/
publicintgetSelectedListIndex(){
returnlistLevel.getSelectedIndex();
}
/**
*返回权限值
*/
publicStringgetSelectedListValue(){
return(String)listLevel.getSelectedValue();
}
/**
*获得窗口确定按钮
*/
publicJButtongetSubmitButton(){
returnbuttonSubmit;
}
/**
*获得窗口帮助按钮
*/
/*publicJButtongetHelpButton(){
returnbuttonHelp;
}*/
/**
*返回用户文本框
*/
publicJTextFieldgetNameField(){
returntfName;
}
/**
*返回密码输入框
*/
publicJPasswordFieldgetPasswordField(){
returnpfPass;
}
/**
*返回列表对象
*/
publicJListgetList(){
returnlistLevel;
}
/**
*添加文本焦点监听
*/
publicvoidaddFieldListener(FocusListenerfl){
this.tfName.addFocusListener(fl);
this.pfPass.addFocusListener(fl);
}
/**
*向控件添加自己的点击事件监听
*
*@paramae:
接受事件源
*/
publicvoidaddButtonListener(ActionListenerae){
this.buttonSubmit.addActionListener(ae);
this.buttonCancel.addActionListener(ae);
this.buttonReset.addActionListener(ae);
//this.buttonHelp.addActionListener(ae);
}
/**
*登录窗口初始化
*/
publicAdminLogin(){
super("用户登录");
this.setIconImage(logoIcon);
this.setFont(font);
this.control();
//标志栏
JPanelpanelWest=newJPanel();
JLabellabelLogo=newJLabel(logoImageIcon);
panelWest.add(labelLogo);
labelLogo.setBorder(BorderFactory.createTitledBorder(""));
//右边登录面板
JPanelpanelEast=newJPanel(newBorderLayout());
JLabellabelTi=newJLabel("提示:
");
labelTi.setFont(fontTitle);
JPanelpanelTop=newJPanel(newGridLayout(2,1));
panelTop.add(labelTi);
labelClew=newJLabel("
"+"
"
+"欢迎使用本系统,请按提示操作!
labelClew.setFont(font);
panelTop.add(labelClew);
panelEast.add("North",panelTop);
//输入框
JPanelpanelInput=newJPanel(newGridLayout(3,1));
JPanelpanelI1=newJPanel(newBorderLayout());
JPanelpanelI2=newJPanel(newBorderLayout());
JLabellabelName=newJLabel("用 户 名:
");
labelName.setFont(font);
JLabellab
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 学校 管理 系统 源码