-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordView.java
More file actions
159 lines (132 loc) · 3.89 KB
/
PasswordView.java
File metadata and controls
159 lines (132 loc) · 3.89 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class PasswordView extends JFrame{
private JButton btn;
private JRadioButton eight;
private JRadioButton sixteen;
private JRadioButton twentyFour;
private JRadioButton thirtyTwo;
private JCheckBox specialChar;
private JCheckBox nums;
private JCheckBox caps;
private JTextField txt;
public PasswordView(){
super( "Random Password" );
Font h = new Font( "Helvetica", Font.PLAIN, 18 );
Color c = Color.decode( "#E1E8E7" );
// instances of the buttons and field
txt = new JTextField( "Push button for random password", 32 );
txt.setHorizontalAlignment( JTextField.CENTER );
txt.setFont( new Font( Font.SANS_SERIF,Font.BOLD, 20 ) );
btn = new JButton( "Generate Password" );
eight = new JRadioButton( "8 Characters", true );
sixteen = new JRadioButton( "16 Characters", false );
twentyFour = new JRadioButton( "24 Characters", false );
thirtyTwo = new JRadioButton( "32 Characters", false );
// font and background color
eight.setFont( h );
sixteen.setFont( h );
twentyFour.setFont( h );
thirtyTwo.setFont( h );
eight.setBackground( c );
sixteen.setBackground( c );
twentyFour.setBackground( c );
thirtyTwo.setBackground( c );
btn.setFont( h );
txt.setBackground( c );
// button group for my radio buttons
ButtonGroup rbg = new ButtonGroup();
rbg.add( eight );
rbg.add( sixteen );
rbg.add( thirtyTwo );
rbg.add( twentyFour );
JPanel radBox = new JPanel();
radBox.setLayout( new GridLayout( 4, 1 ) );
// setting borders for the JPanel
radBox.setBorder( BorderFactory.createLineBorder( Color.black) );
radBox.add( eight );
radBox.add( sixteen );
radBox.add( twentyFour );
radBox.add( thirtyTwo );
// instances of check boxes
specialChar = new JCheckBox( "Special Characters" );
nums = new JCheckBox( "Numbers" );
caps = new JCheckBox( "Capitals" );
// fonts and background
nums.setFont( h );
caps.setFont( h );
specialChar.setFont( h );
nums.setBackground( c );
caps.setBackground( c );
specialChar.setBackground( c );
// JPanel for check boxes
JPanel chBox = new JPanel();
chBox.setLayout( new GridLayout( 3, 1 ) );
// setting borders for the JPanel
chBox.setBorder( BorderFactory.createLineBorder( Color.black ));
chBox.add( nums );
chBox.add( caps );
chBox.add( specialChar );
JPanel buttons = new JPanel();
buttons.setLayout( new BorderLayout( 3, 3 ) );
buttons.add( chBox, BorderLayout.EAST );
buttons.add( radBox, BorderLayout.WEST );
// layout
setLayout( new FlowLayout( FlowLayout.CENTER, 10 , 40 ) );
add( txt );
add( buttons );
add( btn );
setSize( 500, 450 );
setResizable( false );
setBackground( Color.BLUE );
setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE );
setVisible( true );
}
public void setController( PasswordController pc ){
// connecting to the controller
btn.addActionListener( pc );
nums.addItemListener( pc );
specialChar.addItemListener( pc );
caps.addItemListener( pc );
addWindowListener( pc );
}
// method sets txt in the field box
public void updateP( String x ){
txt.setText( x );
}
// method sets caps to true if selected
public boolean selectCaps(){
boolean x = false;
if( caps.isSelected() )
x = true;
return x;
}
// mehtod sets special characters to true if selected
public boolean selectSpecial(){
boolean x = false;
if( specialChar.isSelected() )
x = true;
return x;
}
// method sets numbers to true if selected
public boolean selectNums(){
boolean x = false;
if( nums.isSelected() )
x = true;
return x;
}
// methods sets the size of password with the radio buttons
public int selectSize(){
int x = 0;
if( eight.isSelected() )
x = 8;
else if( sixteen.isSelected() )
x = 16;
else if( twentyFour.isSelected() )
x = 24;
else if( thirtyTwo.isSelected() )
x = 32;
return x;
}
}