Advertisement
Dar954826

Generatore Password[ITA].java

Mar 10th, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.34 KB | None | 0 0
  1. import java.awt.EventQueue;
  2. import javax.swing.JFrame;
  3. import javax.swing.JPanel;
  4. import javax.swing.border.EmptyBorder;
  5. import javax.swing.JCheckBox;
  6. import javax.swing.JTextField;
  7. import javax.swing.JSpinner;
  8. import javax.swing.JLabel;
  9. import javax.swing.JButton;
  10. import java.awt.event.ActionListener;
  11. import java.awt.event.ActionEvent;
  12. import java.awt.event.MouseAdapter;
  13. import java.awt.event.MouseEvent;
  14. import java.util.concurrent.ThreadLocalRandom;
  15. import javax.swing.SpinnerNumberModel;
  16. import javax.swing.JTextArea;
  17. import java.awt.event.KeyAdapter;
  18. import java.awt.event.KeyEvent;
  19. import java.awt.Color;
  20.  
  21. public class Password extends JFrame {
  22.     private static final long serialVersionUID = 1L;
  23.     private JPanel contentPane;
  24.     private JTextField textField;
  25.     private JTextField textField_1;
  26.  
  27.     public static void main(String[] args) {
  28.         EventQueue.invokeLater(new Runnable() {
  29.             public void run() {
  30.                 try {
  31.                     Password frame = new Password();
  32.                     frame.setVisible(true);
  33.                 } catch (Exception e) {
  34.                     e.printStackTrace();
  35.                 }
  36.             }
  37.         });
  38.     }
  39.  
  40.     public Password() {
  41.         setBackground(Color.BLACK);
  42.         setForeground(Color.CYAN);
  43.         setTitle("Generatore Password");
  44.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  45.         setBounds(100, 100, 450, 326);
  46.         contentPane = new JPanel();
  47.         contentPane.setBackground(Color.BLACK);
  48.         contentPane.setForeground(Color.CYAN);
  49.         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  50.         setContentPane(contentPane);
  51.         contentPane.setLayout(null);
  52.  
  53.         JCheckBox chckbxNumeri = new JCheckBox("Numeri");
  54.         chckbxNumeri.setBackground(Color.BLACK);
  55.         chckbxNumeri.setForeground(Color.CYAN);
  56.         chckbxNumeri.setSelected(true);
  57.         chckbxNumeri.setBounds(6, 7, 97, 23);
  58.         contentPane.add(chckbxNumeri);
  59.  
  60.         JCheckBox chckbxLettereMaiuscole = new JCheckBox("Lettere Maiuscole");
  61.         chckbxLettereMaiuscole.setBackground(Color.BLACK);
  62.         chckbxLettereMaiuscole.setForeground(Color.CYAN);
  63.         chckbxLettereMaiuscole.setBounds(137, 7, 120, 23);
  64.         contentPane.add(chckbxLettereMaiuscole);
  65.  
  66.         JCheckBox chckbxLettereMinuscole = new JCheckBox("Lettere minuscole");
  67.         chckbxLettereMinuscole.setBackground(Color.BLACK);
  68.         chckbxLettereMinuscole.setForeground(Color.CYAN);
  69.         chckbxLettereMinuscole.setBounds(308, 7, 120, 23);
  70.         contentPane.add(chckbxLettereMinuscole);
  71.  
  72.         JLabel lblSeparatore = new JLabel("Separatore");
  73.         lblSeparatore.setBackground(Color.BLACK);
  74.         lblSeparatore.setForeground(Color.CYAN);
  75.         lblSeparatore.setVisible(false);
  76.         lblSeparatore.setBounds(0, 78, 64, 14);
  77.         contentPane.add(lblSeparatore);
  78.  
  79.         JSpinner spinner_1 = new JSpinner();
  80.         spinner_1.setBackground(Color.BLACK);
  81.         spinner_1.setForeground(Color.CYAN);
  82.         spinner_1.setVisible(false);
  83.         spinner_1.setModel(new SpinnerNumberModel(5, 1, 300, 1));
  84.         spinner_1.setBounds(64, 103, 55, 20);
  85.         contentPane.add(spinner_1);
  86.  
  87.         JLabel lblSeparaOgni = new JLabel("Separa ogni");
  88.         lblSeparaOgni.setBackground(Color.BLACK);
  89.         lblSeparaOgni.setForeground(Color.CYAN);
  90.         lblSeparaOgni.setVisible(false);
  91.         lblSeparaOgni.setBounds(64, 78, 71, 14);
  92.         contentPane.add(lblSeparaOgni);
  93.  
  94.         JCheckBox chckbxSeparatore = new JCheckBox("Separatore");
  95.         chckbxSeparatore.setBackground(Color.BLACK);
  96.         chckbxSeparatore.setForeground(Color.CYAN);
  97.         chckbxSeparatore.addMouseListener(new MouseAdapter() {
  98.             @Override
  99.             public void mouseClicked(MouseEvent arg0) {
  100.                 if (chckbxSeparatore.isSelected()) {
  101.                     lblSeparaOgni.setVisible(true);
  102.                     lblSeparatore.setVisible(true);
  103.                     spinner_1.setVisible(true);
  104.                     textField_1.setVisible(true);
  105.                 } else {
  106.                     lblSeparaOgni.setVisible(false);
  107.                     lblSeparatore.setVisible(false);
  108.                     spinner_1.setVisible(false);
  109.                     textField_1.setVisible(false);
  110.                 }
  111.             }
  112.         });
  113.         chckbxSeparatore.setBounds(6, 33, 97, 23);
  114.         contentPane.add(chckbxSeparatore);
  115.  
  116.         JCheckBox chckbxCaratteriSpeciali = new JCheckBox("Caratteri speciali");
  117.         chckbxCaratteriSpeciali.setBackground(Color.BLACK);
  118.         chckbxCaratteriSpeciali.setForeground(Color.CYAN);
  119.         chckbxCaratteriSpeciali.setBounds(137, 33, 120, 23);
  120.         contentPane.add(chckbxCaratteriSpeciali);
  121.  
  122.         textField = new JTextField();
  123.         textField.setBackground(Color.BLACK);
  124.         textField.setForeground(Color.CYAN);
  125.         textField.setVisible(false);
  126.         textField.setBounds(287, 103, 141, 20);
  127.         contentPane.add(textField);
  128.         textField.setColumns(10);
  129.  
  130.         JLabel lblInserireCaratteri = new JLabel("Inserire caratteri");
  131.         lblInserireCaratteri.setBackground(Color.BLACK);
  132.         lblInserireCaratteri.setForeground(Color.CYAN);
  133.         lblInserireCaratteri.setVisible(false);
  134.         lblInserireCaratteri.setBounds(315, 78, 109, 14);
  135.         contentPane.add(lblInserireCaratteri);
  136.  
  137.         JCheckBox chckbxCaratteriPersonali = new JCheckBox(
  138.                 "Caratteri Personali");
  139.         chckbxCaratteriPersonali.setBackground(Color.BLACK);
  140.         chckbxCaratteriPersonali.setForeground(Color.CYAN);
  141.         chckbxCaratteriPersonali.addMouseListener(new MouseAdapter() {
  142.             @Override
  143.             public void mouseClicked(MouseEvent e) {
  144.                 if (chckbxCaratteriPersonali.isSelected()) {
  145.                     lblInserireCaratteri.setVisible(true);
  146.                     textField.setVisible(true);
  147.                 } else {
  148.                     lblInserireCaratteri.setVisible(false);
  149.                     textField.setVisible(false);
  150.                     textField.setText("");
  151.                 }
  152.             }
  153.         });
  154.         chckbxCaratteriPersonali.setBounds(308, 33, 120, 23);
  155.         contentPane.add(chckbxCaratteriPersonali);
  156.  
  157.         JSpinner spinner = new JSpinner();
  158.         spinner.setBackground(Color.BLACK);
  159.         spinner.setForeground(Color.CYAN);
  160.         spinner.setModel(new SpinnerNumberModel(5, 1, 600, 1));
  161.         spinner.setBounds(27, 159, 55, 20);
  162.         contentPane.add(spinner);
  163.  
  164.         JLabel lblLunghezzaPassword = new JLabel("Lunghezza Password");
  165.         lblLunghezzaPassword.setBackground(Color.BLACK);
  166.         lblLunghezzaPassword.setForeground(Color.CYAN);
  167.         lblLunghezzaPassword.setBounds(10, 134, 109, 14);
  168.         contentPane.add(lblLunghezzaPassword);
  169.  
  170.         JTextArea lblNewLabel = new JTextArea("");
  171.         lblNewLabel.setBackground(Color.BLACK);
  172.         lblNewLabel.setForeground(Color.CYAN);
  173.         lblNewLabel.setEditable(false);
  174.         lblNewLabel.setBounds(6, 190, 422, 87);
  175.         contentPane.add(lblNewLabel);
  176.  
  177.         JButton btnNewButton = new JButton("Genera");
  178.         btnNewButton.setBackground(Color.BLACK);
  179.         btnNewButton.setForeground(Color.CYAN);
  180.         btnNewButton.addMouseListener(new MouseAdapter() {
  181.             @Override
  182.             public void mouseClicked(MouseEvent e) {
  183.                 lblNewLabel.setText("");
  184.                 String num = "0123456789";
  185.                 String upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  186.                 String lower = "abcdefghijklmnopqrstuvwxyz";
  187.                 String special = "!#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ ";
  188.                 int spin = (Integer) spinner.getValue();
  189.                 String extra = textField.getText();
  190.                 int lol = (Integer) spinner_1.getValue();
  191.                 int adm = 0;
  192.                 while (lblNewLabel.getText().length() <= spin) {
  193.                     int log = ThreadLocalRandom.current().nextInt(0, 7);
  194.                     if (log == 1 & chckbxNumeri.isSelected()) {
  195.                         int m = ThreadLocalRandom.current().nextInt(0,
  196.                                 num.length());
  197.                         char n = num.charAt(m);
  198.                         String o = Character.toString(n);
  199.                         lblNewLabel.setText(lblNewLabel.getText() + o);
  200.                     }
  201.                     if (log == 2 & chckbxLettereMaiuscole.isSelected()) {
  202.                         int m = ThreadLocalRandom.current().nextInt(0,
  203.                                 upper.length());
  204.                         char n = upper.charAt(m);
  205.                         String o = Character.toString(n);
  206.                         lblNewLabel.setText(lblNewLabel.getText() + o);
  207.                     }
  208.  
  209.                     if (log == 3 & chckbxLettereMinuscole.isSelected()) {
  210.                         int m = ThreadLocalRandom.current().nextInt(0,
  211.                                 lower.length());
  212.                         char n = lower.charAt(m);
  213.                         String o = Character.toString(n);
  214.                         lblNewLabel.setText(lblNewLabel.getText() + o);
  215.                     }
  216.                     if (log == 4 & chckbxCaratteriSpeciali.isSelected()) {
  217.                         int m = ThreadLocalRandom.current().nextInt(0,
  218.                                 special.length());
  219.                         char n = special.charAt(m);
  220.                         String o = Character.toString(n);
  221.                         lblNewLabel.setText(lblNewLabel.getText() + o);
  222.                     }
  223.                     if (log == 5 & textField.getText().length() != 0) {
  224.                         int m = ThreadLocalRandom.current().nextInt(0,
  225.                                 extra.length());
  226.                         char n = extra.charAt(m);
  227.                         String o = Character.toString(n);
  228.                         lblNewLabel.setText(lblNewLabel.getText() + o);
  229.                     }
  230.                     if (lblNewLabel.getText().length() % 60 == 0
  231.                             & lblNewLabel.getText().length() > 5) {
  232.                         lblNewLabel.setText(lblNewLabel.getText() + "\n");
  233.                         spin++;
  234.                     }
  235.  
  236.                     if (chckbxSeparatore.isSelected()
  237.                             & lblNewLabel.getText().length() == lol + adm) {
  238.                         lblNewLabel.setText(lblNewLabel.getText()
  239.                                 + textField_1.getText());
  240.                         lol = lol + (Integer) spinner_1.getValue();
  241.                         adm++;
  242.                     }
  243.                 }
  244.                 lblNewLabel.setText(lblNewLabel.getText().substring(0, spin));
  245.             }
  246.         });
  247.         btnNewButton.addActionListener(new ActionListener() {
  248.             public void actionPerformed(ActionEvent arg0) {
  249.             }
  250.         });
  251.         btnNewButton.setBounds(151, 156, 89, 23);
  252.         contentPane.add(btnNewButton);
  253.  
  254.         textField_1 = new JTextField();
  255.         textField_1.setBackground(Color.BLACK);
  256.         textField_1.setForeground(Color.CYAN);
  257.         textField_1.setVisible(false);
  258.         textField_1.setText("-");
  259.         textField_1.addKeyListener(new KeyAdapter() {
  260.             @Override
  261.             public void keyPressed(KeyEvent arg0) {
  262.                 if (textField_1.getText().length() > 0) {
  263.                     textField_1.setText(textField_1.getText().substring(0, 0));
  264.                 }
  265.  
  266.             }
  267.         });
  268.         textField_1.setBounds(6, 100, 22, 23);
  269.         contentPane.add(textField_1);
  270.         textField_1.setColumns(10);
  271.  
  272.     }
  273. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement