📄 login.java
字号:
/*
* Login.java
*
* Created on 2007年7月28日, 上午10:17
*/
package kehu;
import java.sql.*;
import javax.swing.JOptionPane;
/**
*
* @author 徐翘
*/
public class Login extends javax.swing.JFrame {
String manInfo;
/** Creates new form Login */
public Login() {
initComponents();
this.setLocationRelativeTo(null);
}
/** 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=" 生成的代码 ">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
tf_id = new javax.swing.JTextField();
tf_psw = new javax.swing.JTextField();
jComboBox1 = new javax.swing.JComboBox();
B_OK = new javax.swing.JButton();
B_NO = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("\u6559\u52a1\u673a\u7ba1\u7406\u7cfb\u7edf\u767b\u9646\u754c\u9762\n");
setResizable(false);
jLabel1.setText(" \u7528\u6237\uff1a");
jLabel2.setText(" \u5bc6\u7801\uff1a");
jLabel3.setText(" \u8eab\u4efd\uff1a");
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "\u5b66\u751f", "\u6559\u5e08", "\u7ba1\u7406\u5458" }));
B_OK.setText("\u786e\u5b9a");
B_OK.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
B_OKActionPerformed(evt);
}
});
B_NO.setText("\u53d6\u6d88");
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(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 90, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(50, 50, 50)
.add(tf_id, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 160, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(layout.createSequentialGroup()
.add(jLabel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(40, 40, 40)
.add(tf_psw, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 160, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(layout.createSequentialGroup()
.add(jLabel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 90, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(50, 50, 50)
.add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 160, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(layout.createSequentialGroup()
.add(40, 40, 40)
.add(B_OK, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 81, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(76, 76, 76)
.add(B_NO, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 81, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(55, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(50, 50, 50)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel1)
.add(tf_id, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(20, 20, 20)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel2)
.add(tf_psw, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(20, 20, 20)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel3)
.add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(47, 47, 47)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(B_OK)
.add(B_NO))
.addContainerGap(65, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void B_OKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_B_OKActionPerformed
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:教务";
Connection con=DriverManager.getConnection(url,"","");
String qs="select psd from sinfo "+"where sno like ?";
PreparedStatement stmt=con.prepareStatement(qs);
stmt.setString(1,tf_id.getText());
ResultSet rs=stmt.executeQuery();
if(rs.next())
{
if(rs.getString(1).equals(tf_psw.getText()));
JOptionPane.showMessageDialog(null,"登录成功");
if(jComboBox1.getSelectedItem().equals("学生"))
{
manInfo="student";
user s=new user(manInfo,tf_id.getText());
s.setVisible(true);
s.setLocationRelativeTo(null);
}
if(jComboBox1.getSelectedItem().equals("教师"))
{
manInfo="teacher";
user t=new user(manInfo,tf_id.getText());
t.setVisible(true);
this.setVisible(false);
}
if(jComboBox1.getSelectedItem().equals("管理员"))
{ manInfo="administrators";
user a=new user(manInfo,tf_id.getText());
a.setVisible(true);}
// this.setVisible(false);
this.setEnabled(!this.isEnabled());
con.close();}
} catch (SQLException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
}//GEN-LAST:event_B_OKActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Login().setVisible(true);
}
});
}
// 变量声明 - 不进行修改//GEN-BEGIN:variables
private javax.swing.JButton B_NO;
private javax.swing.JButton B_OK;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JTextField tf_id;
private javax.swing.JTextField tf_psw;
// 变量声明结束//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -