package menu;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import dao.DbConnection;
public class gg extends DbConnection{
public static void main(String[] args){
final JFrame jFrame = new JFrame("系统管理员登陆界面");
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
jFrame.setBounds(((int)dimension.getWidth() - 200) / 2, ((int)dimension.getHeight() - 300) / 2, 300, 200);
jFrame.setResizable(false);
jFrame.setLayout(null);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label1 = new JLabel("姓名");
label1.setBounds(30, 10, 100, 30);
jFrame.add(label1);
JLabel label2 = new JLabel("密码");
label2.setBounds(30, 40, 100, 30);
jFrame.add(label2);
final JTextField text1 = new JTextField();
text1.setBounds(70, 15, 130, 20);
jFrame.add(text1);
final JPasswordField text2 = new JPasswordField();
text2.setBounds(70, 45, 130, 20);
jFrame.add(text2);
final JButton button = new JButton("登录");
button.setBounds(70, 75, 60, 40);
JButton button1 = new JButton("取消");
button1.setBounds(130, 75, 60, 40);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Connection con = DbConnection.getConnection();
Statement sta;
ResultSet rs;
try {
sta = con.createStatement();
System.out.println("Connection Successful!"); //如果连接成功 控制台输出Connection Successful!
String f=text1.getText();
rs = sta.executeQuery("select * from ff where account='"+f+"'");
while( rs.next()){
String userName = rs.getString(1);
String passwrod1 =rs.getString(2);
if(userName.equals(text1.getText())){
if(userName.equals(text1.getText())&& passwrod1.equals(text2.getText())) {
JOptionPane.showMessageDialog(null, "登陆成功", "提示", JOptionPane.INFORMATION_MESSAGE);
jFrame.setVisible(false);
new Welcome().Welcome();
} else {
JOptionPane.showMessageDialog(null, "密码错误", "提示", JOptionPane.ERROR_MESSAGE);
text1.setText("");
text2.setText("");
}}else{
JOptionPane.showMessageDialog(null, "用户不存在", "提示", JOptionPane.ERROR_MESSAGE);
}}
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
);
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
performExit();
}
});
jFrame.add(button);
jFrame.add(button1);
jFrame.setVisible(true);
}
protected static void performExit() {
if (JOptionPane.showConfirmDialog(null, "确定退出本系统", "确认",
JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
System.exit(0);
}
}}