/*导入JAVA包*/
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.border.*;
/*******************************************************************
以下是创建*学生信息管理系统*登陆界面程序块
*******************************************************************/
class TRdenglu{//创建登陆界面类
JFrame TRkuangjia1=new JFrame("学生信息管理系统");//登陆界面主框架
JPanel TRmianban=new JPanel();//主面板 用来放置子面板
JPanel TRmianban1=new JPanel();//面板1 用来放置标签1
JPanel TRmianban2=new JPanel();//面板2 用来放置标签2和文本框
JPanel TRmianban3=new JPanel();//面板3 用来放置标签3和密码框
JPanel TRmianban4=new JPanel();//面板4 用来放置登陆和取消按钮
JLabel TRbiaoqian1=new JLabel("欢迎使用学生信息管理系统");
JLabel TRbiaoqian2=new JLabel("帐号:");
JLabel TRbiaoqian3=new JLabel("密码:");
JButton TRanliu1=new JButton("登陆");
JButton TRanliu2=new JButton("取消");
JTextField TRyonhuming=new JTextField(10);
JPasswordField TRmima=new JPasswordField(10);
public void TRfangfa1(){
TRmima.setEchoChar('●');
TRmianban1.add(TRbiaoqian1);
TRmianban2.add(TRbiaoqian2);
TRmianban2.add(TRyonhuming);
TRmianban3.add(TRbiaoqian3);
TRmianban3.add(TRmima);
TRmianban4.add(TRanliu1);
TRmianban4.add(TRanliu2);
TRanliu1.setToolTipText("<html><font color=#ff0000>输入帐号和密码后,点击此按钮可进入-学生信息管理系统-主界面</font></html>");
TRanliu2.setToolTipText("<html><font color=#ff0000>点击此按钮可退出-学生信息管理系统-</font></html>");
JRootPane TRquesheng=TRkuangjia1.getRootPane();//设置登陆按钮为确省按钮
TRquesheng.setDefaultButton(TRanliu1);
TRmianban.add(TRmianban1);
TRmianban.add(TRmianban2);
TRmianban.add(TRmianban3);
TRmianban.add(TRmianban4);
TRkuangjia1.add(TRmianban);
TRkuangjia1.setResizable(false);
TRmianban.setLayout(new BoxLayout(TRmianban,BoxLayout.PAGE_AXIS));
TRkuangjia1.setSize(400,250);
TRkuangjia1.setLocation(200,200);
TRkuangjia1.setVisible(true);
TRjianting1 TR1=new TRjianting1();//创建监听对象1
TRjianting2 TR2=new TRjianting2();//创建监听对象2
TRanliu1.addActionListener(TR1);//对登陆按钮注册监听
TRanliu2.addActionListener(TR2);//对取消按钮注册监听
}
class TRjianting1 implements ActionListener{//对登陆按钮进行监听
public void actionPerformed(ActionEvent e){
String name = TRyonhuming.getText().toString();
String paswd= new String (TRmima.getPassword());
if(name.equals("")||paswd.equals(""))
{
JOptionPane.showMessageDialog(null,"用户名和密码不能为空!","警告",JOptionPane.WARNING_MESSAGE);
}
else
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=DengLu";
Connection conn=DriverManager.getConnection(url);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from DengLuKu where ZhangHao='"+name+"' and MiMa='"+paswd+"'";ResultSet rs=stmt.executeQuery(sql);
if(rs.next())
{
if(e.getSource()==TRanliu1)
{
TRkuangjia1.setVisible(false);
SwingTest TR3=new SwingTest();
}
}
else
{
JOptionPane.showMessageDialog(null,"用户名或密码错误!","警告",JOptionPane.WARNING_MESSAGE);
}
}
catch(SQLException e2)
{
}
catch(ClassNotFoundException e3)
{
}
}
}
}
class TRjianting2 implements ActionListener{//对取消按钮进行监听
public void actionPerformed(ActionEvent e){
int returnValue;
returnValue=JOptionPane.showConfirmDialog(null,"确定要取消登陆并且退出程序吗?","退出",JOptionPane.YES_NO_OPTION);
if(returnValue==JOptionPane.YES_OPTION){
System.exit(0);
}
}
}
public static void main(String[] args){
TRdenglu TR=new TRdenglu();
TR.TRfangfa1();
}
}
/*******************************************************************
以下是创建*学生信息管理系统*主界面程序块
*******************************************************************/
class TRmenu{
JFrame TRkuangjia2=new JFrame("学生信息管理系统--主界面");
JPanel TRmianban5=new JPanel();
JLabel TRbiaoqian4=new JLabel("<html><font color=#0000ff><b><br>欢迎使用学生信息管理系统<br><b></font></html>");
JLabel TRbiaoqian5=new JLabel();
JMenuBar TRcaidanlan=new JMenuBar();
JMenu TRcaidanzhu=new JMenu("系统");
JMenu TRcaidanzhu1=new JMenu("学生信息管理");
JMenu TRcaidanzhu2=new JMenu("学生成绩管理");
JMenu TRcaidanzhu3=new JMenu("帮助");
JMenuItem TRcaidanxiang=new JMenuItem("注销");
JMenuItem TRcaidanxiang1=new JMenuItem("学生信息查询");
JMenuItem TRcaidanxiang2=new JMenuItem("学生信息修改");
JMenuItem TRcaidanxiang3=new JMenuItem("学生信息删除");
JMenuItem TRcaidanxiang4=new JMenuItem("学生信息添加");
JMenuItem TRcaidanxiang5=new JMenuItem("学生信息统计");
JMenuItem TRcaidanxiang6=new JMenuItem("学生成绩查询");
JMenuItem TRcaidanxiang7=new JMenuItem("学生成绩修改");
JMenuItem TRcaidanxiang8=new JMenuItem("学生成绩删除");
JMenuItem TRcaidanxiang9=new JMenuItem("学生成绩添加");
JMenuItem TRcaidanxiang10=new JMenuItem("学生成绩统计");
JMenuItem TRcaidanxiang11=new JMenuItem("关于系统");
JMenuItem TRcaidanxiang12=new JMenuItem("我们的团队");
JMenuItem TRcaidanxiang13=new JMenuItem("主界面");
JMenuItem TRcaidanxiang14=new JMenuItem("退出程序");
public void TRfangfa2(){
TRkuangjia2.add(TRmianban5);
TRkuangjia2.setJMenuBar(TRcaidanlan);
TRkuangjia2.setLocation(200,200);
TRkuangjia2.setResizable(false);
TRbiaoqian5.setIcon(new ImageIcon("taoran.png"));
TRmianban5.add(TRbiaoqian4);
TRmianban5.add(TRbiaoqian5);
TRcaidanlan.add(TRcaidanzhu);
TRcaidanlan.add(TRcaidanzhu1);
TRcaidanlan.add(TRcaidanzhu2);
TRcaidanlan.add(TRcaidanzhu3);
TRcaidanzhu.add(TRcaidanxiang);
TRcaidanzhu.add(TRcaidanxiang13);
TRcaidanzhu.add(TRcaidanxiang14);
TRcaidanzhu1.add(TRcaidanxiang1);
TRcaidanzhu1.add(TRcaidanxiang2);
TRcaidanzhu1.add(TRcaidanxiang3);
TRcaidanzhu1.add(TRcaidanxiang4);
TRcaidanzhu1.add(TRcaidanxiang5);
TRcaidanzhu2.add(TRcaidanxiang6);
TRcaidanzhu2.add(TRcaidanxiang7);
TRcaidanzhu2.add(TRcaidanxiang8);
TRcaidanzhu2.add(TRcaidanxiang9);
TRcaidanzhu2.add(TRcaidanxiang10);
TRcaidanzhu3.add(TRcaidanxiang11);
TRcaidanzhu3.add(TRcaidanxiang12);
TRcaidanxiang.setMnemonic('Q');//创建菜单项快捷键
TRcaidanxiang.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,InputEvent.CTRL_MASK));
TRcaidanxiang13.setMnemonic('M');
TRcaidanxiang13.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M,InputEvent.CTRL_MASK));
TRcaidanxiang14.setMnemonic('N');
TRcaidanxiang14.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,InputEvent.CTRL_MASK));
TRcaidanxiang1.setMnemonic('A');//创建菜单项快捷键
TRcaidanxiang1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A,InputEvent.CTRL_MASK));
TRcaidanxiang2.setMnemonic('B');
TRcaidanxiang2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B,InputEvent.CTRL_MASK));
TRcaidanxiang3.setMnemonic('C');
TRcaidanxiang3.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK));
TRcaidanxiang4.setMnemonic('D');
TRcaidanxiang4.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D,InputEvent.CTRL_MASK));
TRcaidanxiang5.setMnemonic('E');
TRcaidanxiang5.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E,InputEvent.CTRL_MASK));
TRcaidanxiang6.setMnemonic('F');
TRcaidanxiang6.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F,InputEvent.CTRL_MASK));
TRcaidanxiang7.setMnemonic('G');
TRcaidanxiang7.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G,InputEvent.CTRL_MASK));
TRcaidanxiang8.setMnemonic('H');
TRcaidanxiang8.setAcc