From 366617640ab9f61580860d043b9f58c19e3b4acb Mon Sep 17 00:00:00 2001 From: nxist2202005014 <1463859337@qq.com> Date: Wed, 26 Jun 2024 09:50:16 +0800 Subject: [PATCH] ADD file via upload --- LoginFrame.java | 93 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 LoginFrame.java diff --git a/LoginFrame.java b/LoginFrame.java new file mode 100644 index 0000000..cc4dd09 --- /dev/null +++ b/LoginFrame.java @@ -0,0 +1,93 @@ +package flowershop.view; + +import java.awt.Font; + +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPasswordField; +import javax.swing.JTextField; +import javax.swing.SwingConstants; + +import flowershop.model.User; +import flowershop.dao.UserDao; +import flowershop.daoimpl.UserDaoImpl; + +public class LoginFrame extends MyFrame { + + private JTextField txtUserid; + private JPasswordField txtpassword; + + public LoginFrame(String title,int width, int height) { + + super(title,width,height); + //TODO + + getContentPane().setLayout(null); + + JLabel label1 = new JLabel(); + label1.setHorizontalAlignment(SwingConstants.RIGHT); + label1.setBounds(51,33,83,30); + label1.setText("账号:"); + label1.setFont(new Font("微软雅黑",Font.PLAIN,15)); + getContentPane().add(label1); + + txtUserid = new JTextField(10); + txtUserid.setText(""); + txtUserid.setBounds(158,33,157,30); + txtUserid.setFont(new Font("微软雅黑",Font.PLAIN,15)); + getContentPane().add(txtUserid); + + JLabel label2 = new JLabel(); + label2.setHorizontalAlignment(SwingConstants.RIGHT); + label2.setBounds(51,85,83,30); + label2.setText("密码:"); + label2.setFont(new Font("微软雅黑",Font.PLAIN,15)); + getContentPane().add(label2); + + txtpassword = new JPasswordField(10); + txtpassword.setText(""); + txtpassword.setBounds(158,85,157,30); + txtpassword.setFont(new Font("微软雅黑",Font.PLAIN,15)); + getContentPane().add(txtpassword); + + JButton btnOK = new JButton(); + btnOK.setText("确定"); + btnOK.setFont(new Font("微软雅黑",Font.PLAIN,15)); + btnOK.setBounds(61, 140, 100, 30); + getContentPane().add(btnOK); + + JButton btnCancel = new JButton(); + btnCancel.setText("取消"); + btnCancel.setFont(new Font("微软雅黑",Font.PLAIN,15)); + btnCancel.setBounds(225,140,100,30); + getContentPane().add(btnCancel); + + btnOK.addActionListener(e->{ + + UserDao accd = new UserDaoImpl(); + + User ac = accd.findById(txtUserid.getText()); + + String tpassword = new String(txtpassword.getPassword()); + + if(ac !=null && tpassword.equals(ac.getPassword())) { + System.out.println("登陆成功! "); + FlowerListFrame plf =new FlowerListFrame("商品列表",1000,700); + plf.setVisible(true); + setVisible(false); + }else { + JLabel label3 = new JLabel("您输入的账户或密码有误,请重新输入!"); + label3.setFont(new Font("微软雅黑",Font.PLAIN,15)); + JOptionPane.showMessageDialog(null,label3,"登录失败",JOptionPane.ERROR_MESSAGE); + } + + }); + + btnCancel.addActionListener(e->{ + //退出系统 + System.exit(0); + }); + } + +}