Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class NastyAss extends JFrame {
- private static final long serialVersionUID = 1L;
- private JPanel contentPane;
- private JTextField textFieldLogin;
- private JPasswordField passwordField;
- public NastyAss() {
- try {
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
- } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException exception) {
- exception.printStackTrace();
- }
- setTitle("Login pls");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 344, 148);
- setLocationRelativeTo(null);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- textFieldLogin = new JTextField();
- textFieldLogin.setBounds(85, 11, 233, 20);
- contentPane.add(textFieldLogin);
- textFieldLogin.setColumns(10);
- JLabel lblUsername = new JLabel("Username:");
- lblUsername.setBounds(10, 14, 65, 14);
- contentPane.add(lblUsername);
- JLabel lblPassword = new JLabel("Password:");
- lblPassword.setBounds(10, 45, 65, 14);
- contentPane.add(lblPassword);
- String username = "danichee";
- String password = "dendi";
- passwordField = new JPasswordField(password);
- passwordField.setBounds(85, 42, 233, 20);
- contentPane.add(passwordField);
- JButton btnLogin = new JButton("Login");
- btnLogin.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent event) {
- char[] pass = passwordField.getPassword();
- if (textFieldLogin.getText().equals(username) && isCorrect(pass)) {
- System.out.println(true);
- } else {
- System.out.println(false);
- }
- }
- });
- btnLogin.setBounds(10, 70, 308, 28);
- contentPane.add(btnLogin);
- }
- private boolean isCorrect(char[] pass) {
- boolean isCorrect = true;
- char[] password = { 'd', 'e', 'n', 'd', 'i' };
- if (pass.length != password.length) {
- isCorrect = false;
- } else {
- isCorrect = Arrays.equals(pass, password);
- }
- Arrays.fill(password, '0');
- return isCorrect;
- }
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- NastyAss frame = new NastyAss();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement