Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JCheckBox;
- import javax.swing.JTextField;
- import javax.swing.JSpinner;
- import javax.swing.JLabel;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.util.concurrent.ThreadLocalRandom;
- import javax.swing.SpinnerNumberModel;
- import javax.swing.JTextArea;
- import java.awt.event.KeyAdapter;
- import java.awt.event.KeyEvent;
- import java.awt.Color;
- public class Password extends JFrame {
- private static final long serialVersionUID = 1L;
- private JPanel contentPane;
- private JTextField textField;
- private JTextField textField_1;
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Password frame = new Password();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- public Password() {
- setBackground(Color.BLACK);
- setForeground(Color.CYAN);
- setTitle("Password Generator");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 450, 326);
- contentPane = new JPanel();
- contentPane.setBackground(Color.BLACK);
- contentPane.setForeground(Color.CYAN);
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- JCheckBox chckbxNumeri = new JCheckBox("Number");
- chckbxNumeri.setBackground(Color.BLACK);
- chckbxNumeri.setForeground(Color.CYAN);
- chckbxNumeri.setSelected(true);
- chckbxNumeri.setBounds(6, 7, 97, 23);
- contentPane.add(chckbxNumeri);
- JCheckBox chckbxLettereMaiuscole = new JCheckBox("Uppercase Letter");
- chckbxLettereMaiuscole.setBackground(Color.BLACK);
- chckbxLettereMaiuscole.setForeground(Color.CYAN);
- chckbxLettereMaiuscole.setBounds(137, 7, 120, 23);
- contentPane.add(chckbxLettereMaiuscole);
- JCheckBox chckbxLettereMinuscole = new JCheckBox("Lowercase Letter");
- chckbxLettereMinuscole.setBackground(Color.BLACK);
- chckbxLettereMinuscole.setForeground(Color.CYAN);
- chckbxLettereMinuscole.setBounds(308, 7, 120, 23);
- contentPane.add(chckbxLettereMinuscole);
- JLabel lblSeparatore = new JLabel("Separator");
- lblSeparatore.setBackground(Color.BLACK);
- lblSeparatore.setForeground(Color.CYAN);
- lblSeparatore.setVisible(false);
- lblSeparatore.setBounds(0, 78, 64, 14);
- contentPane.add(lblSeparatore);
- JSpinner spinner_1 = new JSpinner();
- spinner_1.setBackground(Color.BLACK);
- spinner_1.setForeground(Color.CYAN);
- spinner_1.setVisible(false);
- spinner_1.setModel(new SpinnerNumberModel(5, 1, 300, 1));
- spinner_1.setBounds(64, 103, 55, 20);
- contentPane.add(spinner_1);
- JLabel lblSeparaOgni = new JLabel("Separates each");
- lblSeparaOgni.setBackground(Color.BLACK);
- lblSeparaOgni.setForeground(Color.CYAN);
- lblSeparaOgni.setVisible(false);
- lblSeparaOgni.setBounds(64, 78, 71, 14);
- contentPane.add(lblSeparaOgni);
- JCheckBox chckbxSeparatore = new JCheckBox("Separator");
- chckbxSeparatore.setBackground(Color.BLACK);
- chckbxSeparatore.setForeground(Color.CYAN);
- chckbxSeparatore.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- if (chckbxSeparatore.isSelected()) {
- lblSeparaOgni.setVisible(true);
- lblSeparatore.setVisible(true);
- spinner_1.setVisible(true);
- textField_1.setVisible(true);
- } else {
- lblSeparaOgni.setVisible(false);
- lblSeparatore.setVisible(false);
- spinner_1.setVisible(false);
- textField_1.setVisible(false);
- }
- }
- });
- chckbxSeparatore.setBounds(6, 33, 97, 23);
- contentPane.add(chckbxSeparatore);
- JCheckBox chckbxCaratteriSpeciali = new JCheckBox("Special character");
- chckbxCaratteriSpeciali.setBackground(Color.BLACK);
- chckbxCaratteriSpeciali.setForeground(Color.CYAN);
- chckbxCaratteriSpeciali.setBounds(137, 33, 120, 23);
- contentPane.add(chckbxCaratteriSpeciali);
- textField = new JTextField();
- textField.setBackground(Color.BLACK);
- textField.setForeground(Color.CYAN);
- textField.setVisible(false);
- textField.setBounds(287, 103, 141, 20);
- contentPane.add(textField);
- textField.setColumns(10);
- JLabel lblInserireCaratteri = new JLabel("Insert character");
- lblInserireCaratteri.setBackground(Color.BLACK);
- lblInserireCaratteri.setForeground(Color.CYAN);
- lblInserireCaratteri.setVisible(false);
- lblInserireCaratteri.setBounds(315, 78, 109, 14);
- contentPane.add(lblInserireCaratteri);
- JCheckBox chckbxCaratteriPersonali = new JCheckBox(
- "Personal character");
- chckbxCaratteriPersonali.setBackground(Color.BLACK);
- chckbxCaratteriPersonali.setForeground(Color.CYAN);
- chckbxCaratteriPersonali.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- if (chckbxCaratteriPersonali.isSelected()) {
- lblInserireCaratteri.setVisible(true);
- textField.setVisible(true);
- } else {
- lblInserireCaratteri.setVisible(false);
- textField.setVisible(false);
- textField.setText("");
- }
- }
- });
- chckbxCaratteriPersonali.setBounds(308, 33, 120, 23);
- contentPane.add(chckbxCaratteriPersonali);
- JSpinner spinner = new JSpinner();
- spinner.setBackground(Color.BLACK);
- spinner.setForeground(Color.CYAN);
- spinner.setModel(new SpinnerNumberModel(5, 1, 600, 1));
- spinner.setBounds(27, 159, 55, 20);
- contentPane.add(spinner);
- JLabel lblLunghezzaPassword = new JLabel("Password Length");
- lblLunghezzaPassword.setBackground(Color.BLACK);
- lblLunghezzaPassword.setForeground(Color.CYAN);
- lblLunghezzaPassword.setBounds(10, 134, 109, 14);
- contentPane.add(lblLunghezzaPassword);
- JTextArea lblNewLabel = new JTextArea("");
- lblNewLabel.setBackground(Color.BLACK);
- lblNewLabel.setForeground(Color.CYAN);
- lblNewLabel.setEditable(false);
- lblNewLabel.setBounds(6, 190, 422, 87);
- contentPane.add(lblNewLabel);
- JButton btnNewButton = new JButton("Generate");
- btnNewButton.setBackground(Color.BLACK);
- btnNewButton.setForeground(Color.CYAN);
- btnNewButton.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- lblNewLabel.setText("");
- String num = "0123456789";
- String upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- String lower = "abcdefghijklmnopqrstuvwxyz";
- String special = "!#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ ";
- int spin = (Integer) spinner.getValue();
- String extra = textField.getText();
- int lol = (Integer) spinner_1.getValue();
- int adm = 0;
- while (lblNewLabel.getText().length() <= spin) {
- int log = ThreadLocalRandom.current().nextInt(0, 7);
- if (log == 1 & chckbxNumeri.isSelected()) {
- int m = ThreadLocalRandom.current().nextInt(0,
- num.length());
- char n = num.charAt(m);
- String o = Character.toString(n);
- lblNewLabel.setText(lblNewLabel.getText() + o);
- }
- if (log == 2 & chckbxLettereMaiuscole.isSelected()) {
- int m = ThreadLocalRandom.current().nextInt(0,
- upper.length());
- char n = upper.charAt(m);
- String o = Character.toString(n);
- lblNewLabel.setText(lblNewLabel.getText() + o);
- }
- if (log == 3 & chckbxLettereMinuscole.isSelected()) {
- int m = ThreadLocalRandom.current().nextInt(0,
- lower.length());
- char n = lower.charAt(m);
- String o = Character.toString(n);
- lblNewLabel.setText(lblNewLabel.getText() + o);
- }
- if (log == 4 & chckbxCaratteriSpeciali.isSelected()) {
- int m = ThreadLocalRandom.current().nextInt(0,
- special.length());
- char n = special.charAt(m);
- String o = Character.toString(n);
- lblNewLabel.setText(lblNewLabel.getText() + o);
- }
- if (log == 5 & textField.getText().length() != 0) {
- int m = ThreadLocalRandom.current().nextInt(0,
- extra.length());
- char n = extra.charAt(m);
- String o = Character.toString(n);
- lblNewLabel.setText(lblNewLabel.getText() + o);
- }
- if (lblNewLabel.getText().length() % 60 == 0
- & lblNewLabel.getText().length() > 5) {
- lblNewLabel.setText(lblNewLabel.getText() + "\n");
- spin++;
- }
- if (chckbxSeparatore.isSelected()
- & lblNewLabel.getText().length() == lol + adm) {
- lblNewLabel.setText(lblNewLabel.getText()
- + textField_1.getText());
- lol = lol + (Integer) spinner_1.getValue();
- adm++;
- }
- }
- lblNewLabel.setText(lblNewLabel.getText().substring(0, spin));
- }
- });
- btnNewButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- }
- });
- btnNewButton.setBounds(151, 156, 89, 23);
- contentPane.add(btnNewButton);
- textField_1 = new JTextField();
- textField_1.setBackground(Color.BLACK);
- textField_1.setForeground(Color.CYAN);
- textField_1.setVisible(false);
- textField_1.setText("-");
- textField_1.addKeyListener(new KeyAdapter() {
- @Override
- public void keyPressed(KeyEvent arg0) {
- if (textField_1.getText().length() > 0) {
- textField_1.setText(textField_1.getText().substring(0, 0));
- }
- }
- });
- textField_1.setBounds(6, 100, 22, 23);
- contentPane.add(textField_1);
- textField_1.setColumns(10);
- }
- }
Add Comment
Please, Sign In to add comment