package com.yz.win;
import com.yz.util.JdbcUtil;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
public class Login {
public Login(){
JFrame jFrame=new JFrame();
jFrame.setTitle("login");
jFrame.setLayout(null);
JButton jButton1=new JButton("登陆");
JButton jButton2 = new JButton("退出");
JLabel jLabel1 = new JLabel("账号");
JLabel jLabel2 = new JLabel("密码");
JLabel jLabel3 = new JLabel("收银员");
JLabel jLabel4 = new JLabel("管理员");
JTextArea jTextArea1 = new JTextArea();
JTextArea jTextArea2 = new JTextArea();
JRadioButton jRadioButton1 = new JRadioButton("管理员");
JRadioButton jRadioButton2 = new JRadioButton("收银员");
jRadioButton1.setSize(80,30);
jRadioButton2.setSize(80,30);
jRadioButton1.setLocation(150,250);
jRadioButton2.setLocation(250,250);
jLabel1.setSize(70,30);
jLabel2.setSize(70,30);
jLabel1.setLocation(100,100);
jLabel2.setLocation(100,200);
jLabel3.setSize(70,30);
jLabel4.setSize(70,30);
jLabel3.setLocation(100,250);
jLabel4.setLocation(300,250);
jButton1.setSize(70,30);
jButton2.setSize(70,30);
jButton1.setLocation(100,300);
jButton2.setLocation(250,300);
jTextArea1.setSize(130,20);
jTextArea1.setLocation(180,100);
jTextArea2.setSize(130,20);
jTextArea2.setLocation(180,200);
jFrame.add(jButton1);
jFrame.add(jButton2);
jFrame.add(jLabel1);
jFrame.add(jLabel2);
jFrame.add(jTextArea1);
jFrame.add(jTextArea2);
jFrame.add(jRadioButton1);
jFrame.add(jRadioButton2);
jFrame.setVisible(true);
jFrame.setSize(500,500);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.setLocation(500,200);
jButton1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String id=jTextArea1.getText().trim();
String password=jTextArea2.getText().trim();
Connection connection=JdbcUtil.getConnection();
String sql="select * from staff where staffNo=?";
PreparedStatement psta=null;
ResultSet res=null;
if (id.equals("") || password.equals("")) {
JOptionPane.showMessageDialog(jFrame, "用户信息不允许为空!");
return;
}
else {
try {
psta=connection.prepareStatement(sql);
psta.setString(1,id);
res=psta.executeQuery();
while (res.next()){
if(password.equals(res.getString(7)))
if(jRadioButton1.isSelected()){
new AdminWin();
jFrame.dispose();
return;
}
else if (jRadioButton2.isSelected()){
new StaffWin();
jFrame.dispose();
return;
}
else {
JOptionPane.showMessageDialog(jFrame,"请选择身份!");
}
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
}
});
jButton2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
jFrame.dispose();
}
});
}
public static void main(String[] args) {
new Login();
}
}
这个超市收银的登陆的账号和密码怎么弄