📄 teachingsystem.java
字号:
/*
* Choose.java
*
* Created on 2007年11月17日, 上午9:13
*/
package javaapplication1;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
/**
*
* @author mis05
*/
public class Teachingsystem extends javax.swing.JFrame {
/** Creates new form Choose */
public Teachingsystem() {
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();
jLabel2 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jPasswordField1 = new javax.swing.JPasswordField();
jButton1 = new javax.swing.JButton();
jRadioButton1 = new javax.swing.JRadioButton();
jLabel3 = new javax.swing.JLabel();
jRadioButton2 = new javax.swing.JRadioButton();
jRadioButton3 = new javax.swing.JRadioButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("\u7528\u6237\u540d");
jLabel2.setText("\u5bc6 \u7801");
jButton1.setText("\u767b\u5f55");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
enter(evt);
}
});
jRadioButton1.setText("\u5b66\u751f");
jRadioButton1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
jRadioButton1.setMargin(new java.awt.Insets(0, 0, 0, 0));
jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
student(evt);
}
});
jLabel3.setFont(new java.awt.Font("宋体", 1, 36));
jLabel3.setText("\u6559\u52a1\u7ba1\u7406\u7cfb\u7edf");
jRadioButton2.setText("\u6559\u5e08");
jRadioButton2.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
jRadioButton2.setMargin(new java.awt.Insets(0, 0, 0, 0));
jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
teacher(evt);
}
});
jRadioButton3.setText("\u6559\u52a1\u7ba1\u7406\u5458");
jRadioButton3.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
jRadioButton3.setMargin(new java.awt.Insets(0, 0, 0, 0));
jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
assistant(evt);
}
});
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(72, 72, 72)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel1)
.add(layout.createSequentialGroup()
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jRadioButton1)
.add(jLabel2))))
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 61, Short.MAX_VALUE)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPasswordField1)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jTextField1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE)))
.add(layout.createSequentialGroup()
.add(34, 34, 34)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jButton1)
.add(layout.createSequentialGroup()
.add(jRadioButton2)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 35, Short.MAX_VALUE)
.add(jRadioButton3))))))
.add(jLabel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.add(84, 84, 84))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(25, 25, 25)
.add(jLabel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 38, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 15, Short.MAX_VALUE)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel1)
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(15, 15, 15)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jLabel2)
.add(jPasswordField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(26, 26, 26)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jRadioButton1)
.add(jRadioButton3)
.add(jRadioButton2))
.add(35, 35, 35)
.add(jButton1)
.add(62, 62, 62))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void assistant(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_assistant
type=jRadioButton3.getText();// TODO add your handling code here:
}//GEN-LAST:event_assistant
private void teacher(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_teacher
type=jRadioButton2.getText();// TODO add your handling code here:
}//GEN-LAST:event_teacher
private void enter(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enter
if( type == "学生" )
{
Statement statement;
String string1=new String(jTextField1.getText());
String string2=new String(jPasswordField1.getPassword());
String string3,string4;
int t=-1;
try{
Conect conect=new Conect();
statement=conect.dbConn.createStatement();
String sql="UPDATE 学生 SET 登录=0 WHERE 登录=1";
int t0=statement.executeUpdate(sql);
string3="SELECT 学生编号 FROM 学生";/*该编号的正确密码*/
ResultSet resultSet1=statement.executeQuery(string3);
ResultSetMetaData metaData1=resultSet1.getMetaData();
int numberOfColumns1=metaData1.getColumnCount();
while(resultSet1.next()){
for(int i=1;i<=numberOfColumns1;i++)
{ if(resultSet1.getObject(i).equals(string1))
t++;
}
}
if(t==0) {
{dispose();
string4="SELECT 密码 FROM 学生 WHERE 学生编号='"+string1+"'";
ResultSet resultSet2=statement.executeQuery(string4);
ResultSetMetaData metaData2=resultSet2.getMetaData();
int numberOfColumns2=metaData2.getColumnCount();
while(resultSet2.next()){
for(int i=1;i<=numberOfColumns2;i++)
{
if(string2.equals(resultSet2.getObject(i).toString()))
{
temp=1;
new Student().setVisible(true);
}
else JOptionPane.showMessageDialog(null,"用户密码不正确","错误",JOptionPane.ERROR_MESSAGE);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -