📄 jiemian.java
字号:
/*
* 登录.java
*
* Created on 2008年9月29日, 下午8:25
*/
package javaapplication1;
import java.sql.*;
import java.util.*;
import java.awt.*;
import javax.swing.*;
/**
*
* @author mis06
*/
public class Jiemian extends javax.swing.JFrame {
/** Creates new form 登录 */
public Jiemian() {
super("教务管理系统");
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
textField = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
Button1 = new javax.swing.JButton();
Button2 = new javax.swing.JButton();
passwordField = new javax.swing.JPasswordField();
jLabel3 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("\u7f16\u53f7");
jLabel2.setText("\u5bc6\u7801");
Button1.setText("\u767b\u5f55");
Button1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Button1ActionPerformed(evt);
}
});
Button2.setText("\u53d6\u6d88");
Button2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Button2ActionPerformed(evt);
}
});
jLabel3.setFont(new java.awt.Font("华文楷体", 1, 24));
jLabel3.setText("\u6b22\u8fce\u4f7f\u7528\u6559\u52a1\u7ba1\u7406\u7cfb\u7edf");
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(46, 46, 46)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(Button1)
.add(42, 42, 42)
.add(Button2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 62, Short.MAX_VALUE))
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel2)
.add(layout.createSequentialGroup()
.add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)))
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(layout.createSequentialGroup()
.add(26, 26, 26)
.add(passwordField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE))
.add(layout.createSequentialGroup()
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(textField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 111, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))))
.add(193, 193, 193))
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jLabel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 258, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(132, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jLabel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 33, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(23, 23, 23)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(textField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel1))
.add(26, 26, 26)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel2)
.add(passwordField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 24, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(36, 36, 36)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(Button2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 27, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(Button1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 29, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap(91, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void Button2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Button2ActionPerformed
System.exit(1);
// TODO add your handling code here:
}//GEN-LAST:event_Button2ActionPerformed
private void Button1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Button1ActionPerformed
Statement statement;
String s1=new String(textField.getText());
String s2=new String(passwordField.getPassword());
String s3="学生",s4="教师",s5="教秘",s6,s7;
int flag=0,n=0;
try{
Connect con=new Connect();
statement=con.con.createStatement();
String str;
str="UPDATE 用户 SET 状态='未登录' WHERE 状态='登录'";
n=statement.executeUpdate(str);
s6="SELECT 密码 FROM 用户 WHERE 编号='"+s1+"'";
ResultSet resultSet1=statement.executeQuery(s6);
ResultSetMetaData metaData1=resultSet1.getMetaData();
int numberOfColumns1=metaData1.getColumnCount();
while(resultSet1.next())
for(int i=1;i<=numberOfColumns1;i++)
{if(resultSet1.getObject(i).toString().equals(s2))
flag++;
}
if(flag==1)
{dispose();
s7="SELECT 类型 FROM 用户 WHERE 编号='"+s1+"'";
ResultSet resultSet2=statement.executeQuery(s7);
ResultSetMetaData metaData2=resultSet2.getMetaData();
int numberOfColumns2=metaData2.getColumnCount();
while(resultSet2.next()){
for(int i=1;i<=numberOfColumns2;i++)
{
if(resultSet2.getObject(i).toString().equals(s3))
{
Student s=new Student();
s.setVisible(true);
}
else
{ if(resultSet2.getObject(i).toString().equals(s4))
{ Teacher t=new Teacher();
t.setVisible(true);
}
else if(resultSet2.getObject(i).toString().equals(s5))
{Secretary se=new Secretary();
se.setVisible(true);}
}
}
}
String s="UPDATE 用户 SET 状态='登录' WHERE 编号='"+s1+"'";
int reg=0;
reg=statement.executeUpdate(s);
}
else JOptionPane.showMessageDialog(null,"用户名或密码不正确,请重新输入");
}
catch(SQLException sqlException){
JOptionPane.showMessageDialog(null,sqlException.getMessage(),"Database Error",JOptionPane.ERROR_MESSAGE);
System.exit(1);}
catch(ClassNotFoundException classNotFound){
JOptionPane.showMessageDialog(null,classNotFound.getMessage(),"Driver Not Found",JOptionPane.ERROR_MESSAGE);
System.exit(1); }
// TODO add your handling code here:
}//GEN-LAST:event_Button1ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Jiemian().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton Button1;
private javax.swing.JButton Button2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPasswordField passwordField;
private javax.swing.JTextField textField;
// End of variables declaration//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -