I have a few classes with in my package, with help from others on here
and Bodyitems ( which is part of the GUI )
Im trying to get it so that the text in the output file becomes the name of the exported.csv file
And i want to have some kind of way of navigating to the file to get the name of the import file using filechooser
TIA
Code:
package gmailcsvapp;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Random;
public class PasswordGenerator {
private CSVParser user;
private CSVParser pass;
public PasswordGenerator()
{
try {
user = new CSVParser("export.csv");
pass = new CSVParser("passwordlist.txt");
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
} catch (EmptyFileException e) {
System.out.println(e.getMessage());
}
generateFirstnames();
generateLastnames();
generateUsernames();
generatePasswords();
try {
user.toFile("exported.csv");
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
}
}
public void generateUsernames()
{
for (int i = 0; i < user.getRowCount(); i++)
{
String[] row = user.getRow(i);
String[] newRow = Arrays.copyOfRange(row, 1, row.length);
String username = row[0].substring(0,1) + "." + row[1];
newRow[0] = username.toLowerCase();
user.setRow(i, newRow);
}
}
public void generateFirstnames()
{
for (int i = 0; i <user.getRowCount(); i++)
{
String[] row =user.getRow(i);
String[] newRow = Arrays.copyOfRange(row,1,row.length);
String firstname = row[0];
user.appendToRow(i,firstname);
}
}
public void generateLastnames()
{
for (int i = 0; i <user.getRowCount(); i++)
{
String[] row =user.getRow(i);
String[] newRow = Arrays.copyOfRange(row,1,row.length);
String lastname = row[1];
user.appendToRow(i,lastname);
}
}
public void generatePasswords()
{
for (int i = 0; i < user.getRowCount(); i++)
{
user.appendToRow(i, getPassword());
}
}
private String getPassword()
{
String[] passwords = pass.getCol(0);
Random rand = new Random();
String pass = passwords[rand.nextInt(passwords.length-1)];
return pass.toLowerCase() + rand.nextInt(100);
}
public static void main(String[] args) {
new Bodyitems();
//* this worked when this was new PasswordGenerator();
}
}
and Bodyitems ( which is part of the GUI )
Code:
package gmailcsvapp;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
*
*
*/
public class Bodyitems extends menuitems{
public Bodyitems ()
{
super();
JButton openButton = new JButton("Open Import");
JLabel Importfilelb = new JLabel("Hello there");
JLabel blank = new JLabel("Enter output file name");
JTextField outputfiletxt = new JTextField("Outputfilename.csv");
JButton outputButton = new JButton("Create New CSV");
outputButton.addActionListener(new outputWatcher());
Container cp = getContentPane();
cp.setLayout(new GridLayout(3, 2));
cp.add(openButton);
cp.add(Importfilelb);
cp.add(blank);
cp.add(outputfiletxt);
cp.add(outputButton);
setVisible(true);
}
private class outputWatcher implements ActionListener
{
public void actionPerformed (ActionEvent a)
{
new PasswordGenerator();
}
}
}
Im trying to get it so that the text in the output file becomes the name of the exported.csv file
And i want to have some kind of way of navigating to the file to get the name of the import file using filechooser
TIA
Last edited: