Advertisement
Gorkhe_Rupesh

LoginForm

Aug 7th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. package javastud;
  2.  
  3. import java.awt.BorderLayout;
  4.  
  5. import java.awt.Color;
  6. import java.awt.EventQueue;
  7.  
  8. import javax.swing.JFrame;
  9. import javax.swing.JPanel;
  10. import javax.swing.border.EmptyBorder;
  11.  
  12. import dao.UserDao;
  13. import dao.UserDaoImpl;
  14.  
  15. import javax.swing.JLabel;
  16. import java.awt.Font;
  17. import java.awt.event.ActionEvent;
  18. import java.awt.event.ActionListener;
  19.  
  20. import javax.swing.JTextField;
  21. import javax.swing.JButton;
  22. import javax.swing.ImageIcon;
  23. import javax.swing.JPasswordField;
  24.  
  25.  
  26. public class LOGIInform extends JFrame {
  27.  
  28. private JPanel contentPane;
  29. private JLabel lblStudentMangementSystem;
  30. private JLabel lblName;
  31. private JTextField usernameTXT;
  32. private JLabel lblPassword;
  33. private JButton btnLogIn;
  34. private JButton btnNewButton;
  35. private JLabel lblNewLabel;
  36. private JPasswordField passwordField;
  37.  
  38. /**
  39. * Launch the application.
  40. */
  41. public static void main(String[] args) {
  42. EventQueue.invokeLater(new Runnable() {
  43. public void run() {
  44. try {
  45. LOGIInform frame = new LOGIInform();
  46. frame.setVisible(true);
  47. } catch (Exception e) {
  48. e.printStackTrace();
  49. }
  50. }
  51. });
  52. }
  53.  
  54. /**
  55. * Create the frame.
  56. */
  57. public LOGIInform() {
  58. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  59. setBounds(100, 100, 807, 706);
  60. contentPane = new JPanel();
  61. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  62. setContentPane(contentPane);
  63. contentPane.setLayout(null);
  64. contentPane.add(getLblStudentMangementSystem());
  65. contentPane.add(getLblName());
  66. contentPane.add(getUsernameTXT());
  67. contentPane.add(getLblPassword());
  68. contentPane.add(getBtnLogIn());
  69. contentPane.add(getBtnNewButton());
  70. contentPane.add(getLblNewLabel());
  71. contentPane.add(getPasswordField());
  72. }
  73. private JLabel getLblStudentMangementSystem() {
  74. if (lblStudentMangementSystem == null) {
  75. lblStudentMangementSystem = new JLabel("STUDENT MANGEMENT SYSTEM ");
  76. lblStudentMangementSystem.setFont(new Font("Tahoma", Font.PLAIN, 23));
  77. lblStudentMangementSystem.setBounds(201, 0, 353, 57);
  78. }
  79. return lblStudentMangementSystem;
  80. }
  81. private JLabel getLblName() {
  82. if (lblName == null) {
  83. lblName = new JLabel("Username");
  84. lblName.setFont(new Font("Tahoma", Font.BOLD, 20));
  85. lblName.setBounds(215, 370, 109, 32);
  86. }
  87. return lblName;
  88. }
  89. private JTextField getUsernameTXT() {
  90. if (usernameTXT == null) {
  91. usernameTXT = new JTextField();
  92. usernameTXT.setBounds(347, 378, 135, 22);
  93. usernameTXT.setColumns(10);
  94. }
  95. return usernameTXT;
  96. }
  97. private JLabel getLblPassword() {
  98. if (lblPassword == null) {
  99. lblPassword = new JLabel("Password");
  100. lblPassword.setFont(new Font("Tahoma", Font.BOLD, 20));
  101. lblPassword.setBounds(226, 405, 109, 32);
  102. }
  103. return lblPassword;
  104. }
  105. private JButton getBtnLogIn() {
  106. if (btnLogIn == null) {
  107. btnLogIn = new JButton("Log In");
  108. btnLogIn.setBounds(256, 490, 109, 25);
  109. btnLogIn.addActionListener(new ActionListener() {
  110.  
  111. @Override
  112. public void actionPerformed(ActionEvent e) {
  113.  
  114. UserDao userDao=new UserDaoImpl();
  115. String username=usernameTXT.getText();
  116. String password=new String(passwordField.getPassword());
  117. boolean isValidUser=userDao.validateUser(username,password);
  118. if(isValidUser) {
  119. studentform studform=new studentform();
  120. studform.setVisible(true);
  121. }else {
  122.  
  123. usernameTXT.setBackground(Color.PINK);
  124. passwordField.setBackground(Color.PINK);
  125. }
  126. }
  127. });
  128. }
  129. return btnLogIn;
  130. }
  131. private JButton getBtnNewButton() {
  132. if (btnNewButton == null) {
  133. btnNewButton = new JButton("Cancel");
  134. btnNewButton.setBounds(365, 490, 109, 25);
  135. }
  136. return btnNewButton;
  137. }
  138. private JLabel getLblNewLabel() {
  139. if (lblNewLabel == null) {
  140. lblNewLabel = new JLabel("New label");
  141. lblNewLabel.setIcon(new ImageIcon("C:\\Users\\Rupesh\\Downloads\\user-logo.217a36f841be.png"));
  142. lblNewLabel.setBounds(134, 57, 479, 286);
  143. }
  144. return lblNewLabel;
  145. }
  146. private JPasswordField getPasswordField() {
  147. if (passwordField == null) {
  148. passwordField = new JPasswordField();
  149. passwordField.setBounds(347, 413, 135, 22);
  150. }
  151. return passwordField;
  152. }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement