Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- Made by Classified; GUI by mjau.
- */
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class GenerateOne extends JFrame implements ActionListener {
- public static int MIN_LENGTH;
- protected static java.util.Random r = new java.util.Random();
- protected static char[] goodChar = { 'a', 'b', 'c', 'd', 'e', 'f', 'g',
- 'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
- 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K',
- 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
- '2', '3', '4', '5', '6', '7', '8', '9', };
- JTextField amount = new JTextField(2);
- JButton generate = new JButton("Generate");
- JLabel length = new JLabel("Length: ");
- String lengthString;
- JTextField outField = new JTextField(15);
- public GenerateOne() {
- super("PassGen");
- setSize(200, 200);
- amount.addActionListener(this);
- generate.addActionListener(this);
- GridBagLayout gridbag = new GridBagLayout();
- GridBagConstraints constraints = new GridBagConstraints();
- setLayout(gridbag);
- constraints.weighty = 3;
- constraints.anchor = GridBagConstraints.EAST;
- constraints.gridwidth = 1;
- gridbag.setConstraints(length, constraints);
- add(length);
- constraints = new GridBagConstraints();
- constraints.gridx = 1;
- constraints.gridwidth = 2;
- constraints.weighty = 3;
- constraints.anchor = GridBagConstraints.CENTER;
- gridbag.setConstraints(amount, constraints);
- add(amount);
- constraints = new GridBagConstraints();
- constraints.gridx = 0;
- constraints.gridy = 1;
- constraints.gridwidth = 3;
- constraints.weighty = 3;
- gridbag.setConstraints(generate, constraints);
- add(generate);
- constraints.gridy = 2;
- constraints.gridwidth = 3;
- constraints.weighty = 3;
- gridbag.setConstraints(outField, constraints);
- add(outField);
- outField.setEditable(false);
- }
- public static String getNext() {
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < MIN_LENGTH; i++) {
- sb.append(goodChar[r.nextInt(goodChar.length)]);
- }
- return sb.toString();
- }
- public void actionPerformed(ActionEvent evt) {
- Object source = evt.getSource();
- if (source == generate) {
- lengthString = amount.getText();
- try {
- MIN_LENGTH = Integer.parseInt(lengthString);
- } catch (Exception e) {
- JOptionPane.showMessageDialog(null, "Please enter a correct value!");
- System.err.println(e);
- }
- outField.setText(GenerateOne.getNext());
- }
- }
- public static void main(String[] args) {
- GenerateOne frame = new GenerateOne();
- frame.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment