diff --git a/src/main/java/userprofilebuilder/view/MainViewer.java b/src/main/java/userprofilebuilder/view/MainViewer.java index b3460be..8eaca70 100644 --- a/src/main/java/userprofilebuilder/view/MainViewer.java +++ b/src/main/java/userprofilebuilder/view/MainViewer.java @@ -6,8 +6,8 @@ package userprofilebuilder.view; import java.awt.*; import javax.swing.*; -import javax.swing.JFrame; import java.awt.event.*; +import java.io.*; /** * @@ -16,17 +16,76 @@ import java.awt.event.*; */ public class MainViewer { public JFrame viewer; + public String file = "userprofile.csv"; - public int a = 3; // this represents a value that is to declare how many rows are to be made -- to be changed by the amount of lines in csv. + public int a = 3; // this represents a value that is to declare how many rows are to be made -- to be changed by the amount of lines in csv. ROW COUNT // start of reader creation - public String Reader() - { - String text = "Default Text -- no reading done."; + public String Reader(int row, String Pname) { + String text = "Default Text"; //hi + String[] values = null; + try (BufferedReader csvReader = new BufferedReader(new FileReader(file))) { + while (csvReader.ready()) { + String line = csvReader.readLine(); + System.out.println(line); + values = line.split(","); + + for (int i =0; i < values.length; i=i+4) + { +// System.out.println(i); +// System.out.println(row); +// System.out.println(values[i].charAt(4)); + + if ( row == Integer.parseInt(String.valueOf(values[i].charAt(4))) ) + { +// System.out.println("row checker passed."); + if (Pname.equals("User Title")) + { + text = values[i+1]; + System.out.println("Set radio button text to :" + text); + return text; + } + else if (Pname.equals("User Name")) { + text = values[i+2]; + System.out.println("Set radio button text to :" + text); + return text; + } + else if (Pname.equals("User Email")) { + text = values[i+3]; + System.out.println("Set radio button text to :" + text); + return text; + } + } + } + } + //assigning them to the correct panel and row. + + // math for it == 4 values per csv row. -> char at [4] of 0 or 4 or 8 --> corresponds to the row it affects. + // get total amount of values. -> 11(array form) -> + 1 then div 4(values per row) = amount of rows needed + // get row. if Pname = "title", RadioB.setText(values[row*4-3]); + // get row. if Pname = "user name", RadioB.setText(values[row*4-2]); + // get row. if Pname = "user email", RadioB.setText(values[row*4-1]); + // if row == values.charAt[4] then do above. + +// for (int i = 0; i < values.length; i++) +// { +// System.out.println(values[i]); +// } + +// System.out.println(row); +// System.out.println(values[0].charAt(4)); + + + } + catch (Exception e) { + System.out.println("error with reader"); + } + +// System.out.println(text); return text; } @@ -41,7 +100,7 @@ public class MainViewer { // Temporary row distinguishing rename - String name = Reader(); + String name = Reader(row, Pname); // end of temporary row rename