package com.wjr.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 com.wjr.dao.impl.AccounttmjImpl; import com.wjr.javaBean.Accounttmj; public class LoginFrame extends MyFrame{ private JTextField txtAccountId; private JPasswordField txtPassword; public LoginFrame(String title, int width, int heigth) { super(title, width, heigth); getContentPane().setLayout(null); JLabel accountLabel=new JLabel(); accountLabel.setHorizontalAlignment(SwingConstants.RIGHT); accountLabel.setBounds(51,33,83,30); accountLabel.setText("用户名"); accountLabel.setFont(new Font("微软雅黑",Font.PLAIN,15)); getContentPane().add(accountLabel); txtAccountId =new JTextField(10); txtAccountId.setText("root"); txtAccountId.setBounds(158,33,157,30); txtAccountId.setFont(new Font("微软雅黑",Font.PLAIN,15)); getContentPane().add(txtAccountId); JLabel passwordLabel=new JLabel(); passwordLabel.setHorizontalAlignment(SwingConstants.RIGHT); passwordLabel.setBounds(51,66,83,30); passwordLabel.setText("密码"); passwordLabel.setFont(new Font("微软雅黑",Font.PLAIN,15)); getContentPane().add(passwordLabel); txtPassword =new JPasswordField(10); txtPassword.setText("*****"); txtPassword.setBounds(158,66,157,30); txtPassword.setFont(new Font("微软雅黑",Font.PLAIN,15)); getContentPane().add(txtPassword); JButton btnlogin = new JButton(); btnlogin.setText("登录"); btnlogin.setFont(new Font("微软雅黑",Font.PLAIN,15)); btnlogin.setBounds(61,140,100,30); getContentPane().add(btnlogin); JButton btnCancel = new JButton(); btnCancel.setText("取消"); btnCancel.setFont(new Font("微软雅黑",Font.PLAIN,15)); btnCancel.setBounds(225,140,100,30); getContentPane().add(btnCancel); btnlogin.addActionListener(e->{ AccounttmjImpl acd = new AccounttmjImpl(); Accounttmj actmj = acd.findByUseridtmj(txtAccountId.getText()); String password =new String(txtPassword.getPassword()); if(actmj != null&& password.equals(actmj.getpasswordtmj())) { System.out.println("成功"); MovieListFrame plf =new MovieListFrame("电影列表",1000,700); plf.setVisible(true); setVisible(false); }else { JLabel lf = new JLabel("错误"); lf.setFont(new Font("微软雅黑",Font.PLAIN,15)); JOptionPane.showMessageDialog(null, lf,"登陆失败",JOptionPane.ERROR_MESSAGE); } }); btnCancel.addActionListener(e->{ System.exit(0); }); } }