⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frame3.java~87~

📁 提供了一种注册机算法的实现. 里面共有两份分别是题库的代码和注册机的代码
💻 JAVA~87~
字号:
package dcwork;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Company: DISCOVERY</p>
 * @author not attributable
 * @version 1.0
 */

public class Frame3 extends JFrame {
 int kk,cc;
  JTextArea jTextArea1 = new JTextArea();
  JPasswordField jPasswordField1 = new JPasswordField();
  JTextField jTextField1 = new JTextField();
  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  JLabel jLabel1 = new JLabel();
  JLabel jLabel2 = new JLabel();
  JLabel jLabel3 = new JLabel();
  JTextField jTextField2 = new JTextField();
  JButton jButton3 = new JButton();
  JTextField jTextField3 = new JTextField();
  JLabel jLabel4 = new JLabel();
  JPasswordField jPasswordField2 = new JPasswordField();

  public Frame3() {
    try {
      jbInit();
    }
    catch(Exception ex) {
      ex.printStackTrace();
    }
  }

  void jbInit() throws Exception {

    jTextArea1.setBackground(UIManager.getColor("InternalFrame.activeTitleGradient"));
    jTextArea1.setEnabled(false);
    jTextArea1.setFont(new java.awt.Font("幼圆", 1, 20));
    jTextArea1.setForeground(Color.black);
    jTextArea1.setBorder(BorderFactory.createEtchedBorder());
    jTextArea1.setToolTipText("");
    jTextArea1.setDisabledTextColor(Color.black);
    jTextArea1.setEditable(false);
    jTextArea1.setText("亲爱的用户,如果您是第一次使用本系统,请您先完成一下一个简单的创建帐号过程,方便您自己以后使用。");
    jTextArea1.setLineWrap(true);
    jTextArea1.setBounds(new Rectangle(29, 29, 365, 90));
    this.getContentPane().setBackground(UIManager.getColor("InternalFrame.activeTitleGradient"));
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.setEnabled(true);
    this.setTitle("注册创建帐号");
    this.getContentPane().setLayout(null);
    this.setResizable(false);
    this.setSize(new Dimension(440,399));
    this.setLocationRelativeTo(null);
    jPasswordField1.setFont(new java.awt.Font("幼圆", 1, 15));
    jPasswordField1.setForeground(Color.red);
    jPasswordField1.setText("");
    jPasswordField1.setEchoChar('●');
    jPasswordField1.setBounds(new Rectangle(174, 171, 217, 34));
    jPasswordField1.addKeyListener(new Frame3_jPasswordField1_keyAdapter(this));
    jTextField1.setFont(new java.awt.Font("幼圆", 1, 15));
    jTextField1.setForeground(Color.blue);
    jTextField1.setText("");

    jTextField1.setBounds(new Rectangle(173, 126, 217, 33));
    jTextField1.addActionListener(new Frame3_jTextField1_actionAdapter(this));
    jButton1.setBounds(new Rectangle(57, 310, 85, 33));
    jButton1.setFont(new java.awt.Font("幼圆", 1, 16));
    jButton1.setToolTipText("");
    jButton1.setText("创建");
    jButton1.addActionListener(new Frame3_jButton1_actionAdapter(this));

    jButton2.setBounds(new Rectangle(309, 311, 80, 33));
    jButton2.setFont(new java.awt.Font("幼圆", 1, 16));
    jButton2.setText("取消");
    jButton2.addActionListener(new Frame3_jButton2_actionAdapter(this));
    jLabel1.setFont(new java.awt.Font("Dialog", 1, 20));
    jLabel1.setText("帐号:");
    jLabel1.setBounds(new Rectangle(68, 129, 64, 34));
    jLabel2.setFont(new java.awt.Font("Dialog", 1, 20));
    jLabel2.setText("密码:");
    jLabel2.setBounds(new Rectangle(67, 173, 63, 37));
    jLabel3.setBounds(new Rectangle(47, 258, 109, 37));
    jLabel3.setText("教师姓名:");
    jLabel3.setFont(new java.awt.Font("Dialog", 1, 20));
    jTextField2.setBounds(new Rectangle(173, 262, 217, 33));
    jTextField2.setText("");
    jTextField2.setForeground(Color.blue);
    jTextField2.setFont(new java.awt.Font("幼圆", 1, 15));
    jButton3.setBounds(new Rectangle(226, 311, 78, 32));
    jButton3.setFont(new java.awt.Font("幼圆", 1, 16));
    jButton3.setText("重来");
    jButton3.addActionListener(new Frame3_jButton3_actionAdapter(this));
    jTextField3.setBorder(null);
    jTextField3.setBounds(new Rectangle(9, 142, 32, 73));
    jLabel4.setFont(new java.awt.Font("Dialog", 1, 20));
    jLabel4.setText("确认密码:");
    jLabel4.setBounds(new Rectangle(46, 218, 128, 37));
    jPasswordField2.setFont(new java.awt.Font("幼圆", 1, 15));
    jPasswordField2.setForeground(Color.red);
    jPasswordField2.setEchoChar('●');
    jPasswordField2.setBounds(new Rectangle(174, 218, 216, 35));
    this.getContentPane().add(jTextArea1, null);
    this.getContentPane().add(jButton2, null);
    this.getContentPane().add(jButton1, null);
    this.getContentPane().add(jButton3, null);
    this.getContentPane().add(jLabel3, null);
    this.getContentPane().add(jLabel2, null);
    this.getContentPane().add(jTextField1, null);
    this.getContentPane().add(jPasswordField1, null);
    this.getContentPane().add(jLabel4, null);
    this.getContentPane().add(jLabel1, null);
    this.getContentPane().add(jTextField2, null);
    this.getContentPane().add(jPasswordField2, null);
    ///////////按键设置焦点
       this.getRootPane().setDefaultButton(jButton1);
       ///////////按键设置焦点



  }

  public static void main(String[] args) {
    Frame3 frame3 = new Frame3();
  }

  void jButton2_actionPerformed(ActionEvent e) {
    Frame1 a=new Frame1();
        a.setVisible(true);
    this.setVisible(false);

  }
//////////////////////////////////////////////////////////////////数据添加
  void jButton1_actionPerformed(ActionEvent e) {
    if(jTextField1.getText().equals("")||jPasswordField1.getText().equals("")){
         JOptionPane.showMessageDialog(this,"姓名或密码不能为空!","注册信息",JOptionPane.INFORMATION_MESSAGE);
    }
   else if(jPasswordField1.getEchoChar()!=jPasswordField2.getEchoChar()){
       JOptionPane.showMessageDialog(this,"你输入的密码前后不一致!","注册信息",JOptionPane.INFORMATION_MESSAGE);}
   else{
        kk=0;
        cc=0;

          Dcyh dc = new Dcyh();
          dc.connection();
          Connection coe=dc.con;
          // ResultSet returnRs = dc.rs;
          Statement s1 = dc.stmt;
          String Input1 = "'"+jTextField1.getText().trim()+"'";
          String Input2= "'"+jPasswordField1.getText().trim()+"'";
          String Input3 = "'"+jTextField2.getText().trim()+"'";
          try {

           ResultSet rsjr=s1.executeQuery("SELECT * FROM yhxx WHERE 用户名="+Input1+"");
if(rsjr.next())
  {JOptionPane.showMessageDialog(this,"    该用户名已经存在!","出错信息",JOptionPane.INFORMATION_MESSAGE);
kk=1;
    jTextField1.setText("") ;
    jTextField1.grabFocus();
}
           ResultSet rsjr2=s1.executeQuery("SELECT * FROM yhxx WHERE 教师姓名="+Input3+"");
if(rsjr2.next())
  {JOptionPane.showMessageDialog(this,"   该教师姓名已经存在!","出错信息",JOptionPane.INFORMATION_MESSAGE);
kk=2;
    jTextField2.setText("") ;
    jTextField2.grabFocus();
}
if(kk==0){
s1.executeUpdate("insert into yhxx(用户名,用户密码,教师姓名) values("+Input1+","+Input2+","+Input3+")");
        JOptionPane.showMessageDialog(this,"注册成功,请记得帐号和密码!","注册信息",JOptionPane.INFORMATION_MESSAGE);

   cc=1;
  }coe.close();
if(cc==1){
   Frame2 a=new Frame2();
            a.setVisible(true);
            this.setVisible(false);
            a.jTextField11111.setText("");
            a.jPasswordField12222.setText("");
            a.jCheckBox1.setSelected(false);
    }
 }
catch (SQLException e3) {System.out.println(e3);}}


}
 ///////////////////////////////////////////////////////////////// 数据添加







class Frame3_jButton2_actionAdapter implements java.awt.event.ActionListener {
  Frame3 adaptee;

  Frame3_jButton2_actionAdapter(Frame3 adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton2_actionPerformed(e);
  }
}

class Frame3_jButton1_actionAdapter implements java.awt.event.ActionListener {
  Frame3 adaptee;

  Frame3_jButton1_actionAdapter(Frame3 adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton1_actionPerformed(e);
  }
}

  void jButton3_actionPerformed(ActionEvent e) {
jTextField1.setText("");
    jTextField2.setText("");
    jPasswordField1.setText("");
    /////////设置焦点
   jTextField1.grabFocus();
   /////////设置焦点

  }

  void jTextField1_actionPerformed(ActionEvent e) {

  }

  void jPasswordField1_keyTyped(KeyEvent e) {

  }}

class Frame3_jButton3_actionAdapter implements java.awt.event.ActionListener {
  Frame3 adaptee;

  Frame3_jButton3_actionAdapter(Frame3 adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton3_actionPerformed(e);
  }
}

class Frame3_jButton1_actionAdapter implements java.awt.event.ActionListener {
  Frame3 adaptee;

  Frame3_jButton1_actionAdapter(Frame3 adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton1_actionPerformed(e);
  }
}

class Frame3_jTextField1_actionAdapter implements java.awt.event.ActionListener {
  Frame3 adaptee;

  Frame3_jTextField1_actionAdapter(Frame3 adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jTextField1_actionPerformed(e);
  }
}

class Frame3_jPasswordField1_keyAdapter extends java.awt.event.KeyAdapter {
  Frame3 adaptee;

  Frame3_jPasswordField1_keyAdapter(Frame3 adaptee) {
    this.adaptee = adaptee;
  }
  public void keyTyped(KeyEvent e) {
    adaptee.jPasswordField1_keyTyped(e);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -