Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import java.security.*;
- import javax.swing.*;
- public class Project06McGinnis extends JFrame implements WindowListener {
- private SecureRandom rand = new SecureRandom();
- private int APP_HEIGHT = 400;
- private int APP_WIDTH = 600;
- private String password ="Your Password Will Appear Here: Pro Tip: Ctrl+c to copy and ctrl+v to paste.";
- private JButton passButton = new JButton( "Create Password" );
- private JTextField Jtxt01 = new JTextField( password );
- private JRadioButton radio1 = new JRadioButton( "8 Characters" );
- private JRadioButton radio2 = new JRadioButton( "12 Characters" );
- private JRadioButton radio3 = new JRadioButton( "16 Characters" );
- private JRadioButton radio4 = new JRadioButton( "32 Characters" );
- private JCheckBox check1 = new JCheckBox( "Include Capital Letters" );
- private JCheckBox check2 = new JCheckBox( "Include Numbers" );
- private JCheckBox check3 = new JCheckBox( "Include Special Characters" );
- private JPanel radioPanel;
- private JPanel checkPanel;
- public Project06McGinnis(){
- setTitle( "Password Maker" );
- setSize( APP_WIDTH, APP_HEIGHT );
- setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE );
- setLayout( new GridLayout( 4,1 ) );
- add( Jtxt01 );
- createRadioPanel();
- createCheckPanel();
- add(passButton);
- setVisible( true );
- addWindowListener( this );
- }
- public void windowClosing( WindowEvent w ){
- int userInput = JOptionPane.showConfirmDialog(
- this,
- "Make sure to copy your password for your records! n (Facebook statuses are a great way to do this!)",
- "Terminate Program?",
- JOptionPane.YES_NO_CANCEL_OPTION
- );
- switch( userInput ){
- case JOptionPane.YES_OPTION:
- System.exit( 0 );
- break;
- }
- }
- @Override
- public void windowOpened(WindowEvent e) {
- }
- @Override
- public void windowClosed(WindowEvent e) {
- }
- @Override
- public void windowIconified(WindowEvent e) {
- }
- @Override
- public void windowDeiconified(WindowEvent e) {
- }
- @Override
- public void windowActivated(WindowEvent e) {
- }
- @Override
- public void windowDeactivated(WindowEvent e) {
- }
- private void createRadioPanel(){
- radioPanel = new JPanel();
- radioPanel.setLayout( new GridLayout( 1, 3,10,10 ) );
- ButtonGroup b = new ButtonGroup();
- b.add( radio1 );
- b.add( radio2 );
- b.add( radio3 );
- b.add( radio4 );
- radioPanel.add( radio1 );
- radioPanel.add( radio2 );
- radioPanel.add( radio3 );
- radioPanel.add( radio4 );
- add( radioPanel );
- }
- private void createCheckPanel(){
- checkPanel = new JPanel();
- checkPanel.setLayout( new GridLayout( 1, 3,10,10 ) );
- checkPanel.add( check1 );
- checkPanel.add( check2 );
- checkPanel.add( check3 );
- add( checkPanel );
- }
- public void actionPerformed( ActionEvent ae ) {
- StringBuilder str = new StringBuilder();
- str.append( lowerCase );
- if( radio1.isSelected() ) {
- str.setLength(8);
- }else if( radio2.isSelected() ) {
- str.setLength(16);
- }else if( radio3.isSelected() ) {
- str.setLength(16);
- }else if( radio4.isSelected() ) {
- str.setLength(32);
- }
- if(check1.isSelected() ) {
- str.append(upperCase);
- }if(check2.isSelected() ) {
- str.append(numbers);
- }if(check3.isSelected() ) {
- str.append(specialChars);
- }
- if( passButton.isSelected() ) {
- password.replace("Your Password Will Appear Here: Pro Tip: Ctrl+c to copy and ctrl+v to paste.", str.toString());
- }
- }
- public static void main(String[] args){
- new Project06McGinnis();
- }
- private String lowerCase = "qwertyuiopasdfghjklzxcvbnm";
- private String upperCase = "QWERTYUIOPASDFGHJKLZXCVBNM";
- private String numbers = "123456789";
- private String specialChars = "!@#$%^&*()_-=+'/?<>,.[]{}|";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement