From c15ec0d0ad1dd5b5646ab9fbbfa102f8b9eb8ccd Mon Sep 17 00:00:00 2001 From: mudabbir-ahmad Date: Tue, 4 Feb 2025 21:59:59 +0000 Subject: [PATCH] =?UTF-8?q?W1R6=20=E2=80=93=20Adding=20Additional=20Tabbed?= =?UTF-8?q?=20Panes=20for=20data=20in=20the=20'userprofile.csv'=20file=20-?= =?UTF-8?q?-=20finished=20CSV=20reader.=20set=20CSV=20file=20to=20userprof?= =?UTF-8?q?ile.csv?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../userprofilebuilder/view/MainViewer.java | 71 +++++++++++++++++-- 1 file changed, 65 insertions(+), 6 deletions(-) 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