📄 frame2.java~68~
字号:
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 Frame2 extends JFrame { public String a; JPasswordField jPasswordField1 = new JPasswordField(); JTextField jTextField1 = new JTextField(); JButton jButton1 = new JButton(); JButton jButton2 = new JButton(); JCheckBox jCheckBox1 = new JCheckBox(); JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); public Frame2() { try { jbInit(); } catch(Exception ex) { ex.printStackTrace(); } } void jbInit() throws Exception { jPasswordField1.setFont(new java.awt.Font("Dialog", 1, 15)); jPasswordField1.setForeground(Color.red); //jPasswordField1.setText(""); jPasswordField1.setBounds(new Rectangle(133, 90, 161, 32)); this.setSize(new Dimension(380,300)); this.setLocationRelativeTo(null); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setLocale(java.util.Locale.getDefault()); this.setResizable(true); this.setState(Frame.NORMAL); this.setTitle("题库登陆界面"); this.getContentPane().setLayout(null); this.setResizable(false); ///////////按键设置焦点 this.getRootPane().setDefaultButton(jButton1); ///////////按键设置焦点 jTextField1.setFont(new java.awt.Font("幼圆", 1, 15)); jTextField1.setForeground(Color.blue); //jTextField1.setText(""); jTextField1.setBounds(new Rectangle(134, 45, 160, 33)); jButton1.setBounds(new Rectangle(86, 185, 101, 38)); jButton1.setFont(new java.awt.Font("Dialog", 0, 15)); jButton1.setFocusPainted(true); jButton1.setText("确定"); jButton1.addActionListener(new Frame2_jButton1_actionAdapter(this)); jButton2.setBounds(new Rectangle(209, 185, 100, 37)); jButton2.setFont(new java.awt.Font("Dialog", 0, 15)); jButton2.setText("取消"); jButton2.addActionListener(new Frame2_jButton2_actionAdapter(this)); jCheckBox1.setFont(new java.awt.Font("Dialog", 1, 15)); jCheckBox1.setActionCommand("记住密码用户"); jCheckBox1.setText("记住密码用户"); jCheckBox1.setBounds(new Rectangle(133, 133, 147, 35)); jLabel1.setFont(new java.awt.Font("幼圆", 1, 16)); jLabel1.setText("用户:"); jLabel1.setBounds(new Rectangle(65, 49, 55, 21)); jLabel2.setFont(new java.awt.Font("幼圆", 1, 16)); jLabel2.setText("密码:"); jLabel2.setBounds(new Rectangle(67, 93, 51, 23)); this.getContentPane().add(jPasswordField1, null); this.getContentPane().add(jCheckBox1, null); this.getContentPane().add(jLabel1, null); this.getContentPane().add(jLabel2, null); this.getContentPane().add(jTextField1, null); this.getContentPane().add(jButton2, null); this.getContentPane().add(jButton1, null); /////////////////////////////////////////////////////////////记住密码(读出)try{ Dcyh jz= new Dcyh(); Statement stemtjz = jz.stmt; Connection fdd=jz.con;//System.out.println("成功"); ResultSet rsjz=stemtjz.executeQuery("SELECT * FROM jzmm WHERE nu='10'"); while(rsjz.next()) {String vv1=rsjz.getString(4);String vv2=rsjz.getString(3);String vv3=rsjz.getString(2); System.out.print(vv1); System.out.print(vv2); System.out.print(vv3);if(vv1!=a){System.out.print(2);jTextField1.setText(vv2);jPasswordField1.setText(vv3); jCheckBox1.isSelected() ;}/*else{System.out.print(3);jTextField1.setText("");jPasswordField1.setText("");}*/ }}catch (SQLException e5a123) {System.err.println(e5a123);}////////////////////////////////////////////////////////////////记住密码(读出) } public static void main(String[] args) { Frame2 frame2 = new Frame2(); } void jButton1_actionPerformed(ActionEvent e) {////////////////////////////////////////////用户密码验证(按钮事件)//int choice= JOptionPane.showConfirmDialog(this,"确定"+name+"进入!","登录",JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);//if(choice==JOptionPane.YES_OPTION){ try{ Dcyh jr = new Dcyh(); Statement stemtjr = jr.stmt; Connection fd=jr.con;//System.out.println("成功"); ResultSet rsjr=stemtjr.executeQuery("SELECT * FROM yhxx WHERE 用户名='"+jTextField1.getText().trim()+"' and 用户密码='"+jPasswordField1.getText().trim()+"'"); if(rsjr.next()) {String vv=rsjr.getString(4); //System.out.println(vv); a=vv;Frame4 a1=new Frame4(a);a1.setVisible(true);this.setVisible(false);//System.out.println("成功"); } else{ JOptionPane.showMessageDialog(this,"你输入的用户名或密码有误!请重新输入.","出错信息!",JOptionPane.WARNING_MESSAGE); jTextField1.setText(""); jPasswordField1.setText(""); /////////设置焦点 jTextField1.grabFocus(); /////////设置焦点 }fd.close(); } catch(SQLException e99){System.out.println(e99);} /*/////////////////////////// */ //////////////////////////////////////////////用户密码验证(按钮事件) /////////////////////////////////////////////记住密码登陆(输入) String tt1=jTextField1.getText(); String tt2=jPasswordField1.getText(); String tt3; if(jCheckBox1.isSelected()) { tt3="a"; Dcyh dcb = new Dcyh(); dcb.connection(); Statement sb = dcb.stmt; Connection fd2=dcb.con; try { sb.executeUpdate("update jzmm set 帐号='"+tt1+"',密码='"+tt2+"',标记='"+tt3+"' where nu='10'"); System.out.println("成功"); fd2.close(); } catch (SQLException e5a1) {System.err.println(e5a1);}} else{tt3="b"; Dcyh dcb2 = new Dcyh(); dcb2.connection(); Statement sb2 = dcb2.stmt; Connection fd3=dcb2.con; try { sb2.executeUpdate("update jzmm set 标记='"+tt3+"' where nu='10'"); System.out.println("成功"); fd3.close(); } catch (SQLException e5a12) {System.err.println(e5a12);}}///////////////////////////////////////////////记住密码登陆(输入) } void jButton2_actionPerformed(ActionEvent e) { Frame1 a=new Frame1(); a.setVisible(true); this.setVisible(false); } void jButton3_actionPerformed(ActionEvent e) { jTextField1.setText(""); jPasswordField1.setText(""); }}class Frame2_jButton1_actionAdapter implements java.awt.event.ActionListener { Frame2 adaptee; Frame2_jButton1_actionAdapter(Frame2 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton1_actionPerformed(e); }}class Frame2_jButton2_actionAdapter implements java.awt.event.ActionListener { Frame2 adaptee; Frame2_jButton2_actionAdapter(Frame2 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton2_actionPerformed(e); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -