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

📄 logodialog.java~41~

📁 行业分类数据库管理系统
💻 JAVA~41~
字号:
package blapp;

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

public class logoDialog extends JDialog {
  private boolean connected = false;
  String user = null;
  String password = null;

  JPanel panel1 = new JPanel();
  JLabel jLabel2 = new JLabel();
  JButton jButton2 = new JButton();
  JButton jButton1 = new JButton();
  JPasswordField jPasswordField1 = new JPasswordField();
  JLabel jLabel1 = new JLabel();
  JTextField jTextField1 = new JTextField();

  public logoDialog(Frame frame, String title, boolean modal) {
    super(frame, title, modal);
    try {
      jbInit();
      pack();
    }
    catch(Exception ex) {
      ex.printStackTrace();
    }
  }

  public logoDialog() {
    this(null, "系统登录", false);
  }
  private void jbInit() throws Exception {
    panel1.setLayout(null);
    jLabel2.setFont(new java.awt.Font("Dialog", 0, 14));
    jLabel2.setToolTipText("");
    jLabel2.setText("密码:");
    jLabel2.setBounds(new Rectangle(31, 98, 53, 23));
    jButton2.setText("取消");
    jButton2.addActionListener(new logoDialog_jButton2_actionAdapter(this));
    jButton2.setBounds(new Rectangle(196, 150, 65, 24));    jButton2.setFont(new java.awt.Font("Dialog", 0, 12));
    jButton2.setBorder(BorderFactory.createEtchedBorder());
    jButton1.setBounds(new Rectangle(125, 150, 65, 24));    jButton1.setFont(new java.awt.Font("Dialog", 0, 12));
    jButton1.setBorder(BorderFactory.createEtchedBorder());
    jButton1.setText("确定");
    jButton1.addActionListener(new logoDialog_jButton1_actionAdapter(this));
    jPasswordField1.setBackground(SystemColor.desktop);    jPasswordField1.setForeground(Color.white);    jPasswordField1.setDebugGraphicsOptions(0);    jPasswordField1.setCaretColor(Color.white);    jPasswordField1.setText("");
    jPasswordField1.setEchoChar('¥');
    jPasswordField1.setBounds(new Rectangle(90, 94, 177, 26));
    jLabel1.setFont(new java.awt.Font("Dialog", 0, 14));
    jLabel1.setText("用户名:");
    jLabel1.setBounds(new Rectangle(31, 47, 59, 23));
    jTextField1.setBackground(SystemColor.desktop);    jTextField1.setForeground(Color.white);
    jTextField1.setText("");
    jTextField1.setBounds(new Rectangle(90, 46, 177, 26));
    panel1.setMinimumSize(new Dimension(300, 200));
    panel1.setPreferredSize(new Dimension(300, 200));
    this.addWindowListener(new logoDialog_this_windowAdapter(this));
    getContentPane().add(panel1);
    panel1.add(jLabel1, null);
    panel1.add(jLabel2, null);
    panel1.add(jTextField1, null);
    panel1.add(jPasswordField1, null);
    panel1.add(jButton1, null);
    panel1.add(jButton2, null);
  }

  void jButton2_actionPerformed(ActionEvent e) {
        System.exit(0);
  }

  void this_windowClosed(WindowEvent e) {
       System.exit(0);
  }

  void this_windowClosing(WindowEvent e) {
       System.exit(0);
  }

  void jButton1_actionPerformed(ActionEvent e) {

    if(connected)
    {

    }

    else
    {
      user = jTextField1.getText().trim();
      password = jPasswordField1.getText().trim();
      String url =
          "jdbc:microsoft:sqlserver://worktwo:1433;DatabaseName=informations";
      String ls_1 = "SELECT * FROM ur WHERE users='" + user + "'" +
          "and password='" + password + "'";
      try {
        Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); //加载驱动程序
        Connection con = DriverManager.getConnection(url, "sa", "b"); //建立连接
        Statement stmt = con.createStatement(); //执行SQL
        ResultSet result = stmt.executeQuery(ls_1); //返回结果
        while (result.next()) {
          //System.out.print(result.getString("users"));

          JOptionPane.showMessageDialog(this, "登录成功!", "提示",
                                        JOptionPane.INFORMATION_MESSAGE);

          this.setVisible(false);
           Frame1 fr = new Frame1(stmt,con);
           result.close();
           Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
               Dimension frameSize = fr.getSize();
               if (frameSize.height > screenSize.height) {
                 frameSize.height = screenSize.height;
               }
               if (frameSize.width > screenSize.width) {
                 frameSize.width = screenSize.width;
               }
               fr.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
               fr.setVisible(true);


          return;
        }
        JOptionPane.showMessageDialog(this, "登录失败,用户名/密码错误。", "提示",
                                      JOptionPane.ERROR_MESSAGE);
      }
      catch (java.lang.Exception ex) {
        JOptionPane.showMessageDialog(this, "系统错误,请与系统管理员联系!", "警告",
                                      JOptionPane.ERROR_MESSAGE);
        System.out.print(ex.toString());
      }
    }
  }
}

class logoDialog_jButton2_actionAdapter implements java.awt.event.ActionListener {
  logoDialog adaptee;

  logoDialog_jButton2_actionAdapter(logoDialog adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton2_actionPerformed(e);
  }
}

class logoDialog_this_windowAdapter extends java.awt.event.WindowAdapter {
  logoDialog adaptee;

  logoDialog_this_windowAdapter(logoDialog adaptee) {
    this.adaptee = adaptee;
  }
  public void windowClosed(WindowEvent e) {
    adaptee.this_windowClosed(e);
  }
  public void windowClosing(WindowEvent e) {
    adaptee.this_windowClosing(e);
  }
}

class logoDialog_jButton1_actionAdapter implements java.awt.event.ActionListener {
  logoDialog adaptee;

  logoDialog_jButton1_actionAdapter(logoDialog adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton1_actionPerformed(e);
  }
}

⌨️ 快捷键说明

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