package hospitals;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.*;
public class denglu extends JFrame {
public static String namew;
public static String user;
public static String user1;
public static String password;
private static final long serialVersionUID=1L;
static jdbc connect=new jdbc();
static java.sql.Connection con=null;
JLabel a=new JLabel("用户名:");
JLabel cuowu=new JLabel("用户名或者密码不对,请重新输入");
JLabel b=new JLabel("密码:");
ImageIcon bj = new ImageIcon("F:/123.jpg");
JLabel label = new JLabel(bj);
JButton c=new JButton("登录");
private boolean flag;
static JTextField d=new JTextField();
static JPasswordField f=new JPasswordField();
denglu(String sTitle){
super(sTitle);
this.setLayout(null);
this.add(cuowu);
this.add(a);
this.add(b);
this.add(c);
this.add(d);
this.add(f);
this.add(label);
cuowu.setBounds(100, 130, 200, 50);
cuowu.setForeground(Color.black);
cuowu.setVisible(false);
label.setBounds(0, -50, 500, 400);
c.addActionListener(new ShowAct());
a.setBounds(10, 10, 100, 50);
a.setFont(new Font("",1,20));
a.setForeground(Color.WHITE);
b.setBounds(10, 90, 100, 50);
b.setForeground(Color.WHITE);
b.setFont(new Font("",1,20));
c.setBounds(20, 180, 100, 50);
c.setBackground(Color.CYAN);
d.setBounds(100, 20, 150, 30);
f.setBounds(100, 100, 150, 30);
this.setSize(400,280); //设置窗口大小
this.setResizable(false); //设置不可调整窗口大小
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true); //窗口显示
}
public static void main (String args[]){
denglu ts=new denglu("医院管理系统");
}
public class ShowAct implements ActionListener {
public boolean flag=false;
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
try {
String name=d.getText().toString();
String x=f.getText().toString();
con=connect.getConnection();
Statement stmt =con.createStatement();
ResultSet rs=stmt.executeQuery("select * from Hospital_Doctor");
while(rs.next()){
user=rs.getString("DrId");
user1=rs.getString("DrName");
password=rs.getString("DrPhone");
if(user.equals(name)&&password.equals(x)){
this.flag=true;
JOptionPane.showMessageDialog(null, "登录成功");
new mainframe("医院管理系统");
denglu.this.setVisible(false);
break;
}
else{
d.setText("");
f.setText("");
cuowu.setVisible(true);
}
}
} catch (SQLException e2) {
// TODO Auto-generated catch block
System.out.println(e2);
}
}
}
}
一键复制
编辑
Web IDE
原始数据
按行查看
历史