Guest User

Untitled

a guest
Jun 29th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.80 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.FlowLayout;
  3.  
  4. import javax.swing.JButton;
  5. import javax.swing.JDialog;
  6. import javax.swing.JOptionPane;
  7. import javax.swing.JPanel;
  8. import javax.swing.border.EmptyBorder;
  9. import javax.swing.JPasswordField;
  10. import javax.swing.JTextField;
  11. import javax.swing.JLabel;
  12. import java.awt.event.ActionListener;
  13. import java.awt.event.ActionEvent;
  14. import java.util.Arrays;
  15.  
  16.  
  17. public class Opdracht2 extends JDialog {
  18.  
  19.     // Variabelen declareren
  20.     int Proberen = 3;
  21.    
  22.     private String Naam;
  23.    
  24.     private final JPanel contentPanel = new JPanel();
  25.     private JPasswordField txtPassword;
  26.     private JTextField txtUsername;
  27.  
  28.     /**
  29.      * Create the dialog.
  30.      */
  31.     public Opdracht2(java.awt.Frame parent, boolean modal) {
  32.         super(parent, modal);
  33.         setSize(320, 160);
  34.         setLocationRelativeTo(null);
  35.         getContentPane().setLayout(new BorderLayout());
  36.         contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
  37.         getContentPane().add(contentPanel, BorderLayout.CENTER);
  38.         contentPanel.setLayout(null);
  39.         {
  40.             txtPassword = new JPasswordField();
  41.             txtPassword.setBounds(155, 33, 116, 20);
  42.             contentPanel.add(txtPassword);
  43.         }
  44.        
  45.         txtUsername = new JTextField();
  46.         txtUsername.setBounds(29, 33, 116, 20);
  47.         contentPanel.add(txtUsername);
  48.         txtUsername.setColumns(10);
  49.        
  50.         JLabel lblNewLabel = new JLabel("Username:");
  51.         lblNewLabel.setBounds(29, 11, 65, 14);
  52.         contentPanel.add(lblNewLabel);
  53.        
  54.         JLabel lblNewLabel_1 = new JLabel("Password:");
  55.         lblNewLabel_1.setBounds(155, 11, 65, 14);
  56.         contentPanel.add(lblNewLabel_1);
  57.         {
  58.             JPanel buttonPane = new JPanel();
  59.             buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
  60.             getContentPane().add(buttonPane, BorderLayout.SOUTH);
  61.             {
  62.                 JButton okButton = new JButton("Login");
  63.                 okButton.addActionListener(new ActionListener() {
  64.                                    
  65.                     public void actionPerformed(ActionEvent arg0)
  66.                     {  
  67.                        
  68.                         String Password = new String(txtPassword.getPassword());
  69.                        
  70. //                      char[] Wachtwoord, Correct;
  71. //                      Wachtwoord = txtPassword.getPassword();
  72. //                      Correct = Password.trim().toCharArray();
  73.                        
  74.                         // Wanneer de onderstaande gegevens hetzelfde zijn, dan wordt er ingelogd
  75.                         if(txtUsername.getText().equals("Muamer") && Password.equals("hoi123"))
  76.                         {
  77.                             Naam = txtUsername.getText();
  78.                             JOptionPane.showMessageDialog(null,"U wordt succesvol ingelogd!");
  79.                             setVisible(false);
  80.                         }
  81.                         // Wanneer de bovenstaande gegevens niet hetzelfde zijn, dan krijg je de onderstaande melding
  82.                          else
  83.                          {
  84.                              Proberen--;
  85.                              if (Proberen == 0)
  86.                              {
  87.                                  JOptionPane.showMessageDialog(null, "U heeft 3 keer geprobeerd om in te loggen, de applicatie wordt hierdoor afgesloten!");
  88.                                  System.exit(0);
  89.                              }
  90.                              else
  91.                              {
  92.                                  JOptionPane.showMessageDialog(null, "U mag nog "+ Proberen + " keer inloggen!");
  93.                              }
  94.                         }
  95.                     }
  96.                 });
  97.                 okButton.setActionCommand("OK");
  98.                 buttonPane.add(okButton);
  99.                 getRootPane().setDefaultButton(okButton);
  100.             }
  101.             {
  102.                 JButton cancelButton = new JButton("Cancel");
  103.                 cancelButton.addActionListener(new ActionListener() {
  104.                     public void actionPerformed(ActionEvent e)
  105.                     {
  106.                         System.exit(0);
  107.                     }
  108.                 });
  109.                 cancelButton.setActionCommand("Cancel");
  110.                 buttonPane.add(cancelButton);
  111.             }
  112.         }
  113.     }
  114.     /**
  115.      * Launch the application.
  116.      */
  117.     public static void main(String[] args) {
  118.         try {
  119.             Opdracht2 dialog = new Opdracht2(new java.awt.Frame(), true);
  120.             dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
  121.             dialog.setVisible(true);
  122.         } catch (Exception e) {
  123.             e.printStackTrace();
  124.         }
  125.     }
  126.    
  127.    
  128.     public String Gebruikersnaam() {
  129.         return Naam;
  130.     }
  131. }
Add Comment
Please, Sign In to add comment