Bonsoir,
Je suis chaud aujourd'hui LOL 2eme post....
Alors voila à fin de terminer ma petite application pour générer un mot de passe il me reste plus qu'à mettre en "fonction" le bouton "New password" j'ai essayé différentes méthodes simples mais sans succès...
Voir entre la ligne 44 - 47 boutonNewPswd
Voici le codes source :
Merci pour le coup de main..
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74 package PassSeb; /********** **By Seb** ***********/ import java.util.Random; import javax.swing.BoxLayout; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import java.awt.Dimension; public class PassWordGenerator { public static void main(String[] args) { int length = 12; // Longueur du mot de passe JFrame frame = new JFrame("PassWordGenerator"); JLabel print = new JLabel(); print.setText(new String(generatePswd(length))); // char[] --> String pour le JLabel print.setAlignmentX(0.5f); print.setAlignmentY(0.5f); print.setPreferredSize(new Dimension(300, 120)); frame.setLocationRelativeTo(null); frame.setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(print); frame.pack(); frame.setVisible(true); JButton boutonQuitter = new JButton("Quitter"); boutonQuitter.setAlignmentX(0.5f); boutonQuitter.addActionListener(e->frame.dispose()); frame.add(boutonQuitter); JButton boutonNewPswd = new JButton("New password"); boutonNewPswd.setAlignmentX(0.5f); //boutonNewPswd.addActionListener(this); frame.add(boutonNewPswd); ImageIcon image = new ImageIcon("cryptee-icone-9007-48.png"); frame.setIconImage(image.getImage()); frame.setVisible(true); } static char[] generatePswd(int len) { String charsCaps = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; String chars = "abcdefghijklmnopqrstuvwxyz"; String nums = "0123456789"; String symbols = "@---------/"; String passSymbols = charsCaps + chars + nums + symbols; Random rnd = new Random(); char[] password = new char[len]; for (int i = 0; i < len; i++) { password[i] = passSymbols.charAt(rnd.nextInt(passSymbols.length())); } return password; } }
Seb
Partager