Project code
package password_generator_app;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
/**
*
* @sreyashbaishkhiyarlenovopc
*/
public class Password_Generator_App extends JFrame {
private JCheckBox lowerCaseCheckBox;
private JCheckBox upperCaseCheckBox;
private JCheckBox numbersCheckBox;
private JCheckBox specialCharsCheckBox;
private JSpinner lengthSpinner;
private JTextField passwordTextField;
private JButton generateButton;
public Password_Generator_App(){
// Set up the JFrame properties
setTitle("Password Generator");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400,400);
setLocationRelativeTo(null);
initialize(); // initialize the user interface
}
private void initialize(){
// Create checkboxes for character type selection
lowerCaseCheckBox = new JCheckBox("Include LowerCase");
upperCaseCheckBox = new JCheckBox("Include UpperCase");
numbersCheckBox = new JCheckBox("Include Numbers");
specialCharsCheckBox = new JCheckBox("Include Special Characters");
[Link](false);
[Link](false);
[Link](new Cursor(Cursor.HAND_CURSOR));
[Link](false);
[Link](false);
[Link](new Cursor(Cursor.HAND_CURSOR));
[Link](false);
[Link](false);
[Link](new Cursor(Cursor.HAND_CURSOR));
[Link](false);
[Link](false);
[Link](new Cursor(Cursor.HAND_CURSOR));
// Create a spinner for password length selection
lengthSpinner = new JSpinner(new SpinnerNumberModel(8,4,20,1));
// Create a text field to display the generated password
passwordTextField = new JTextField(20);
[Link](new Font("Arial", [Link], 16));
[Link](false);
// Create a button to generate passwords
generateButton = new JButton("Generate Password");
[Link](new Color(63,81,181));
[Link]([Link]);
[Link](false);
[Link](false);
[Link](new Cursor(Cursor.HAND_CURSOR));
[Link](new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
generatePassword();
}
});
// Create panels to hold UI components
JPanel mainPanel = new JPanel(new GridLayout(8,1,10,10));
[Link]([Link](20,20,20,20));
[Link]([Link]);
[Link](lowerCaseCheckBox);
[Link](upperCaseCheckBox);
[Link](numbersCheckBox);
[Link](specialCharsCheckBox);
JPanel lengthPanel = new JPanel(new FlowLayout([Link]));
[Link]([Link]);
[Link](new JLabel("Password Length"));
[Link](lengthSpinner);
[Link](lengthPanel);
JPanel buttonPanel = new JPanel(new FlowLayout([Link]));
[Link]([Link]);
[Link](generateButton);
[Link](buttonPanel);
[Link](passwordTextField);
getContentPane().setBackground([Link]);
add(mainPanel);
private String generatePassword()
{
// Get the desired password length from the spinner
int passwordLength = (int) [Link]();
// Define character sets for password generation
String lowerCase = "abcdefghijklmnopqrstuvwxyz";
String upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String numbers = "0123456789";
String specialChars = "!@#$%^&*()_+-=[]{}|;:,.<>?";
// Initialize the characters string based on user selections
String characters = "";
if([Link]()) characters += lowerCase;
if([Link]()) characters += upperCase;
if([Link]()) characters += numbers;
if([Link]()) characters += specialChars;
// If no character type is selected, show an error message
if ([Link]())
{
[Link](this, "Please Select at Least one Character
type");
return "";
}
// Generate the password by selecting random characters from the characters string
Random random = new Random();
StringBuilder password = new StringBuilder();
for(int i = 0; i < passwordLength; i++)
{
int randomIndex = [Link]([Link]());
char randomChar = [Link](randomIndex);
[Link](randomChar);
}
// Display the generated password in the text field
[Link]([Link]());
return [Link]();
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
[Link](() -> {
try
{
[Link]("[Link]");
}
catch(Exception ex)
{
[Link]();
}
Password_Generator_App app = new Password_Generator_App();
[Link](true);
});
Outputs