web123456

Based on Java Swing Student Information Management System

  • package ;
  • import ;
  • import ;
  • import ;
  • import ;
  • import ;
  • import ;
  • import ;
  • import ;
  • import ;
  • import ;
  • import ;
  • import ;
  • import ;
  • import ;
  • public class LoginFrame extends JFrame
  • {
  • private static final long serialVersionUID = 7305643042548754587L;
  • JButton btnLogin;
  • JButton btnCancel;
  • JTextField txtUsername;
  • JPasswordField txtPassword;
  • MyDB myDB=new MyDB();
  • public LoginFrame()
  • {
  • setSize(400,200);
  • setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  • setResizable(false);
  • setLocationRelativeTo(null);
  • setTitle("Login");
  • JLabel lblUsername=new JLabel("Account number:");
  • JLabel lblPassword=new JLabel("Password:");
  • txtUsername=new JTextField(30);
  • txtPassword=new JPasswordField(30);
  • JPanel panelUsername=new JPanel();
  • (lblUsername);
  • (txtUsername);
  • JPanel panelPassword=new JPanel();
  • (lblPassword);
  • (txtPassword);
  • btnLogin=new JButton("OK.");
  • btnCancel=new JButton("Reset.");
  • JPanel btnPanel=new JPanel();
  • (btnLogin);
  • (btnCancel);
  • JPanel coutainer=new JPanel();
  • (panelUsername);
  • (panelPassword);
  • (btnPanel);
  • add(coutainer);
  • addListeners();
  • setVisible(true);
  • }
  • public void addListeners()
  • {
  • ActionListener btnLoginClick= new ActionListener()
  • {
  • @Override
  • public void actionPerformed(ActionEvent e)
  • {
  • Student student=new Student();
  • (());
  • int result= new LoginDao().select(()+"", ()+"");
  • if(result>0)
  • {
  • (null, "Login successful.");
  • setVisible(false);
  • MainFrame mainFrame =new MainFrame();
  • (true);
  • }
  • else{
  • (null, "Wrong username or password.");
  • }
  • }
  • };
  • (btnLoginClick);
  • }
  • }