Advertisement
Guest User

Untitled

a guest
Aug 29th, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. public class NastyAss extends JFrame {
  2.  
  3. private static final long serialVersionUID = 1L;
  4.  
  5. private JPanel contentPane;
  6. private JTextField textFieldLogin;
  7. private JPasswordField passwordField;
  8.  
  9. public NastyAss() {
  10.  
  11. try {
  12. UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  13. } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException exception) {
  14. exception.printStackTrace();
  15. }
  16.  
  17. setTitle("Login pls");
  18. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  19. setBounds(100, 100, 344, 148);
  20. setLocationRelativeTo(null);
  21. contentPane = new JPanel();
  22. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  23. setContentPane(contentPane);
  24. contentPane.setLayout(null);
  25.  
  26. textFieldLogin = new JTextField();
  27. textFieldLogin.setBounds(85, 11, 233, 20);
  28. contentPane.add(textFieldLogin);
  29. textFieldLogin.setColumns(10);
  30.  
  31. JLabel lblUsername = new JLabel("Username:");
  32. lblUsername.setBounds(10, 14, 65, 14);
  33. contentPane.add(lblUsername);
  34.  
  35. JLabel lblPassword = new JLabel("Password:");
  36. lblPassword.setBounds(10, 45, 65, 14);
  37. contentPane.add(lblPassword);
  38.  
  39. String username = "danichee";
  40. String password = "dendi";
  41.  
  42. passwordField = new JPasswordField(password);
  43. passwordField.setBounds(85, 42, 233, 20);
  44. contentPane.add(passwordField);
  45.  
  46. JButton btnLogin = new JButton("Login");
  47. btnLogin.addActionListener(new ActionListener() {
  48. public void actionPerformed(ActionEvent event) {
  49. char[] pass = passwordField.getPassword();
  50.  
  51. if (textFieldLogin.getText().equals(username) && isCorrect(pass)) {
  52. System.out.println(true);
  53. } else {
  54. System.out.println(false);
  55. }
  56. }
  57. });
  58. btnLogin.setBounds(10, 70, 308, 28);
  59. contentPane.add(btnLogin);
  60. }
  61.  
  62. private boolean isCorrect(char[] pass) {
  63. boolean isCorrect = true;
  64.  
  65. char[] password = { 'd', 'e', 'n', 'd', 'i' };
  66.  
  67. if (pass.length != password.length) {
  68. isCorrect = false;
  69. } else {
  70. isCorrect = Arrays.equals(pass, password);
  71. }
  72.  
  73. Arrays.fill(password, '0');
  74.  
  75. return isCorrect;
  76. }
  77.  
  78. public static void main(String[] args) {
  79. EventQueue.invokeLater(new Runnable() {
  80. public void run() {
  81. try {
  82. NastyAss frame = new NastyAss();
  83. frame.setVisible(true);
  84. } catch (Exception e) {
  85. e.printStackTrace();
  86. }
  87. }
  88. });
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement