📄 login.java~68~
字号:
package clinique;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.sql.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.Rectangle;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.sql.Statement;
import java.sql.Connection;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class login extends JFrame {
JPanel contentPane;
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JTextField jTextField1 = new JTextField();
JPasswordField jPasswordField1 = new JPasswordField();
static String username;
String userpassword;
boolean password=false;
public login() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(320, 230));
setTitle("用户登陆");
jButton1.setBounds(new Rectangle(67, 139, 64, 23));
jButton1.setText("登陆");
jButton1.addActionListener(new login_jButton1_actionAdapter(this));
jButton2.setBounds(new Rectangle(175, 137, 60, 23));
jButton2.setText("取消");
jButton2.addActionListener(new login_jButton2_actionAdapter(this));
jLabel1.setText("用户名:");
jLabel1.setBounds(new Rectangle(61, 46, 42, 15));
jLabel2.setText("密码:");
jLabel2.setBounds(new Rectangle(74, 99, 42, 15));
jTextField1.setBounds(new Rectangle(145, 43, 94, 20));
jPasswordField1.setBounds(new Rectangle(145, 91, 94, 24));
contentPane.add(jButton2);
contentPane.add(jButton1);
contentPane.add(jLabel2);
contentPane.add(jLabel1);
contentPane.add(jTextField1);
contentPane.add(jPasswordField1);
}
public void jButton1_actionPerformed(ActionEvent e) {
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
} catch (ClassNotFoundException ce) {
System.out.println(ce);
}
try {
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=clinique";
Connection con = DriverManager.getConnection(url,"sa","");
Statement s = con.createStatement();
ResultSet rs = s.executeQuery("select * from doctor where name=\'"+jTextField1.getText()+"\' and password=\'"+String.valueOf(jPasswordField1.getPassword())+"\'");
while (rs.next()) {
password = true;
}
if (password == true) {
username=jTextField1.getText();
userpassword=jPasswordField1.getText();
JOptionPane.showMessageDialog(null,username);
dispose();
main_frame m = new main_frame();
m.setSize(800,600);
m.setVisible(true);
m.setResizable(false);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = m.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
m.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
} else {
JOptionPane.showMessageDialog(null, "用户名不存在或密码错误,请重新输入!",
"Error", JOptionPane.WARNING_MESSAGE);
jTextField1.requestFocus();
jTextField1.setText("");
jPasswordField1.setText("");
}
rs.close();
s.close();
con.close();
} catch (SQLException ce) {
System.out.println(ce);
}
}
public void jButton2_actionPerformed(ActionEvent e) {
System.exit(0);
}
}
class login_jButton1_actionAdapter implements ActionListener {
private login adaptee;
login_jButton1_actionAdapter(login adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class login_jButton2_actionAdapter implements ActionListener {
private login adaptee;
login_jButton2_actionAdapter(login adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -