Advertisement
Guest User

Untitled

a guest
Sep 12th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. package Login;
  2.  
  3. import java.awt.EventQueue;
  4. import javax.swing.JFrame;
  5. import javax.swing.JLabel;
  6. import javax.swing.JOptionPane;
  7. import javax.swing.JSeparator;
  8. import javax.swing.JTextField;
  9. import javax.swing.JPasswordField;
  10. import javax.swing.JCheckBox;
  11. import java.awt.Font;
  12. import javax.swing.JButton;
  13. import java.awt.event.ActionListener;
  14. import java.awt.event.ActionEvent;
  15. import javax.swing.JToggleButton;
  16. import javax.swing.JTextPane;
  17.  
  18. public class LI {
  19.  
  20. private JFrame frame;
  21. private JTextField textField;
  22. private JPasswordField passwordField;
  23.  
  24. /**
  25. * Launch the application.
  26. */
  27. public static void main(String[] args) {
  28. EventQueue.invokeLater(new Runnable() {
  29. public void run() {
  30. try {
  31. LI window = new LI();
  32. window.frame.setVisible(true);
  33. } catch (Exception e) {
  34. e.printStackTrace();
  35. }
  36. }
  37. });
  38. }
  39.  
  40. /**
  41. * Create the application.
  42. */
  43. public LI() {
  44. initialize();
  45. }
  46.  
  47. /**
  48. * Initialize the contents of the frame.
  49. */
  50. private void initialize() {
  51. frame = new JFrame("Log In v1.1");
  52. frame.setBounds(100, 100, 450, 300);
  53. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  54. frame.getContentPane().setLayout(null);
  55.  
  56. JLabel LogIa = new JLabel("Log In");
  57. LogIa.setFont(new Font("Tahoma", Font.BOLD, 14));
  58. LogIa.setBounds(179, 24, 78, 31);
  59. frame.getContentPane().add(LogIa);
  60.  
  61. JLabel username = new JLabel("Username");
  62. username.setBounds(44, 91, 71, 14);
  63. frame.getContentPane().add(username);
  64.  
  65. JLabel password = new JLabel("Password");
  66. password.setBounds(44, 145, 71, 14);
  67. frame.getContentPane().add(password);
  68.  
  69. JSeparator separator = new JSeparator();
  70. separator.setBounds(44, 193, 326, -4);
  71. frame.getContentPane().add(separator);
  72.  
  73. JSeparator separator_1 = new JSeparator();
  74. separator_1.setBounds(44, 53, 326, 2);
  75. frame.getContentPane().add(separator_1);
  76.  
  77. textField = new JTextField();
  78. textField.setBounds(150, 88, 127, 20);
  79. frame.getContentPane().add(textField);
  80. textField.setColumns(10);
  81.  
  82. passwordField = new JPasswordField();
  83. passwordField.setBounds(150, 142, 127, 20);
  84. frame.getContentPane().add(passwordField);
  85.  
  86. JCheckBox rembUser = new JCheckBox("Remember Username");
  87. rembUser.setFont(new Font("Tahoma", Font.PLAIN, 9));
  88. rembUser.setBounds(237, 112, 133, 23);
  89.  
  90. frame.getContentPane().add(rembUser);
  91.  
  92. JButton btnLogIn = new JButton("Log In");
  93. btnLogIn.addActionListener(new ActionListener() {
  94. public void actionPerformed(ActionEvent e) {
  95. String username = textField.getText();
  96. @SuppressWarnings("deprecation")
  97. String password = passwordField.getText();
  98.  
  99. if (username.contains("admin") && password.contains("admin") && rembUser.isSelected()==false) {
  100. passwordField.setText(null);
  101. textField.setText(null);
  102. }
  103. else if (rembUser.isSelected()==true ){
  104. JOptionPane.showMessageDialog(null, "Invaild Details","Login Failed", JOptionPane.ERROR_MESSAGE);
  105. passwordField.setText(null);
  106. }
  107. else if (username.contains("admin") && password.contains("admin") && rembUser.isSelected()==true ) {
  108. passwordField.setText(null);
  109.  
  110. }
  111.  
  112. else if (username.isEmpty() || password.isEmpty()) {
  113. JOptionPane.showMessageDialog(btnLogIn, "Password or Username is not filled!", "Invaild Login", JOptionPane.INFORMATION_MESSAGE);
  114. }
  115. else {
  116. JOptionPane.showMessageDialog(btnLogIn, "Invaild Details", "Login Failed", JOptionPane.ERROR_MESSAGE);
  117. }
  118. }
  119. });
  120. btnLogIn.setBounds(44, 201, 89, 23);
  121. frame.getContentPane().add(btnLogIn);
  122.  
  123. JButton btnReset = new JButton("Reset");
  124. btnReset.addActionListener(new ActionListener() {
  125. public void actionPerformed(ActionEvent e) {
  126. if(rembUser.isSelected()==true ) {
  127. passwordField.setText(null);
  128.  
  129. }
  130. else {
  131. textField.setText(null);
  132. passwordField.setText(null);
  133. }
  134. }
  135. });
  136. btnReset.setBounds(168, 200, 89, 23);
  137. frame.getContentPane().add(btnReset);
  138.  
  139. JButton btnExit = new JButton("Exit");
  140. btnExit.addActionListener(new ActionListener() {
  141. public void actionPerformed(ActionEvent e) {
  142. if ( JOptionPane.showConfirmDialog(btnExit, "Are you sure you want to exit ?" ,"Exit " , JOptionPane.YES_NO_OPTION)== JOptionPane.YES_NO_OPTION) {
  143. System.exit(0);
  144. }
  145. }
  146. });
  147. btnExit.setFont(new Font("Tahoma", Font.BOLD, 11));
  148. btnExit.setBounds(281, 201, 89, 23);
  149. frame.getContentPane().add(btnExit);
  150. }
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement