Advertisement
Guest User

Untitled

a guest
Apr 6th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.security.*;
  4. import javax.swing.*;
  5.  
  6.  
  7. public class Project06McGinnis extends JFrame implements WindowListener {
  8.  
  9. private SecureRandom rand = new SecureRandom();
  10. private int APP_HEIGHT = 400;
  11. private int APP_WIDTH = 600;
  12. private String password ="Your Password Will Appear Here: Pro Tip: Ctrl+c to copy and ctrl+v to paste.";
  13.  
  14. private JButton passButton = new JButton( "Create Password" );
  15. private JTextField Jtxt01 = new JTextField( password );
  16. private JRadioButton radio1 = new JRadioButton( "8 Characters" );
  17. private JRadioButton radio2 = new JRadioButton( "12 Characters" );
  18. private JRadioButton radio3 = new JRadioButton( "16 Characters" );
  19. private JRadioButton radio4 = new JRadioButton( "32 Characters" );
  20.  
  21.  
  22. private JCheckBox check1 = new JCheckBox( "Include Capital Letters" );
  23. private JCheckBox check2 = new JCheckBox( "Include Numbers" );
  24. private JCheckBox check3 = new JCheckBox( "Include Special Characters" );
  25.  
  26. private JPanel radioPanel;
  27. private JPanel checkPanel;
  28.  
  29. public Project06McGinnis(){
  30.  
  31. setTitle( "Password Maker" );
  32. setSize( APP_WIDTH, APP_HEIGHT );
  33. setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE );
  34. setLayout( new GridLayout( 4,1 ) );
  35. add( Jtxt01 );
  36. createRadioPanel();
  37. createCheckPanel();
  38. add(passButton);
  39. setVisible( true );
  40. addWindowListener( this );
  41. }
  42.  
  43.  
  44. public void windowClosing( WindowEvent w ){
  45. int userInput = JOptionPane.showConfirmDialog(
  46. this,
  47. "Make sure to copy your password for your records! n (Facebook statuses are a great way to do this!)",
  48. "Terminate Program?",
  49. JOptionPane.YES_NO_CANCEL_OPTION
  50. );
  51. switch( userInput ){
  52. case JOptionPane.YES_OPTION:
  53. System.exit( 0 );
  54. break;
  55. }
  56.  
  57. }
  58.  
  59.  
  60. @Override
  61. public void windowOpened(WindowEvent e) {
  62.  
  63. }
  64.  
  65.  
  66. @Override
  67. public void windowClosed(WindowEvent e) {
  68.  
  69. }
  70.  
  71. @Override
  72. public void windowIconified(WindowEvent e) {
  73.  
  74. }
  75.  
  76. @Override
  77. public void windowDeiconified(WindowEvent e) {
  78.  
  79. }
  80.  
  81. @Override
  82. public void windowActivated(WindowEvent e) {
  83.  
  84. }
  85.  
  86. @Override
  87. public void windowDeactivated(WindowEvent e) {
  88.  
  89. }
  90. private void createRadioPanel(){
  91.  
  92. radioPanel = new JPanel();
  93. radioPanel.setLayout( new GridLayout( 1, 3,10,10 ) );
  94.  
  95. ButtonGroup b = new ButtonGroup();
  96. b.add( radio1 );
  97. b.add( radio2 );
  98. b.add( radio3 );
  99. b.add( radio4 );
  100.  
  101. radioPanel.add( radio1 );
  102. radioPanel.add( radio2 );
  103. radioPanel.add( radio3 );
  104. radioPanel.add( radio4 );
  105.  
  106. add( radioPanel );
  107. }
  108.  
  109. private void createCheckPanel(){
  110.  
  111. checkPanel = new JPanel();
  112. checkPanel.setLayout( new GridLayout( 1, 3,10,10 ) );
  113. checkPanel.add( check1 );
  114. checkPanel.add( check2 );
  115. checkPanel.add( check3 );
  116.  
  117. add( checkPanel );
  118. }
  119.  
  120. public void actionPerformed( ActionEvent ae ) {
  121.  
  122. StringBuilder str = new StringBuilder();
  123. str.append( lowerCase );
  124.  
  125. if( radio1.isSelected() ) {
  126. str.setLength(8);
  127. }else if( radio2.isSelected() ) {
  128. str.setLength(16);
  129. }else if( radio3.isSelected() ) {
  130. str.setLength(16);
  131. }else if( radio4.isSelected() ) {
  132. str.setLength(32);
  133. }
  134.  
  135. if(check1.isSelected() ) {
  136. str.append(upperCase);
  137. }if(check2.isSelected() ) {
  138. str.append(numbers);
  139. }if(check3.isSelected() ) {
  140. str.append(specialChars);
  141. }
  142.  
  143. if( passButton.isSelected() ) {
  144. password.replace("Your Password Will Appear Here: Pro Tip: Ctrl+c to copy and ctrl+v to paste.", str.toString());
  145. }
  146.  
  147.  
  148. }
  149.  
  150. public static void main(String[] args){
  151. new Project06McGinnis();
  152. }
  153.  
  154. private String lowerCase = "qwertyuiopasdfghjklzxcvbnm";
  155. private String upperCase = "QWERTYUIOPASDFGHJKLZXCVBNM";
  156. private String numbers = "123456789";
  157. private String specialChars = "!@#$%^&*()_-=+'/?<>,.[]{}|";
  158.  
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement