From 4b65140f17aa9fa5bd6a832d0e3a37323c23fdb5 Mon Sep 17 00:00:00 2001 From: mudabbir-ahmad Date: Sat, 15 Feb 2025 16:45:57 +0000 Subject: [PATCH] =?UTF-8?q?W4R3=20=E2=80=93=20'UserProfile'=20Button=20Pan?= =?UTF-8?q?el?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../userprofilebuilder/model/UserGroup.java | 21 +++++++++++-- .../userprofilebuilder/view/MainViewer.java | 31 +++++++++++++++++-- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/main/java/userprofilebuilder/model/UserGroup.java b/src/main/java/userprofilebuilder/model/UserGroup.java index 820d8fe..47c0c5c 100644 --- a/src/main/java/userprofilebuilder/model/UserGroup.java +++ b/src/main/java/userprofilebuilder/model/UserGroup.java @@ -52,17 +52,32 @@ public class UserGroup { return text; } - public static void SaveFor(JTabbedPane jt, String file) + public static void SaveFor(String file, JFrame viewer, int TotalRows) { String[] values = null; try (BufferedReader csvReader = new BufferedReader(new FileReader(file))) { - while (csvReader.ready()) { + + + JPanel mainPane = (JPanel) viewer.getContentPane(); + JTabbedPane jt = (JTabbedPane) mainPane.getComponent(0); + + for (int i=0; i<3; i++) + { String line = csvReader.readLine(); values = line.split(","); - + JPanel jp1 = (JPanel) jt.getComponentAt(i); // tab + for (int rows = 0; rows < TotalRows; rows++){ + JPanel jp2 = (JPanel) jp1.getComponent(rows); + JRadioButton jr1 = (JRadioButton) jp2.getComponent(0); + //System.out.println(jr1.getText()); + values[i] = jr1.getText(); + } } + + + } catch (Exception e) { System.out.println("error with reader"); diff --git a/src/main/java/userprofilebuilder/view/MainViewer.java b/src/main/java/userprofilebuilder/view/MainViewer.java index ca2a87c..e770847 100644 --- a/src/main/java/userprofilebuilder/view/MainViewer.java +++ b/src/main/java/userprofilebuilder/view/MainViewer.java @@ -23,6 +23,7 @@ public class MainViewer { public JFrame viewer; public String file = "userprofile.csv"; public ArrayList radioButtons = new ArrayList<>(); + int TotalRows; 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 @@ -88,8 +89,10 @@ public class MainViewer { jp.add(RowPanel); group.add(JR); + radioButtons.add(JR); + System.out.println("Row number: "+ row + " Has been created!"); ActionListener EditListener = e -> { @@ -149,7 +152,7 @@ public class MainViewer { public void TabMaker(String Pname, JTabbedPane JT) { - ButtonGroup group = new ButtonGroup(); + ButtonGroup group = new ButtonGroup(); // getting button count -> also a way to get number of total rows. JPanel page = new JPanel(); page.setLayout(new GridLayout(0,1)); // Because i cant remember the orientation of grid layout params it's (x,y) AKA rows , columns @@ -168,6 +171,28 @@ public class MainViewer { { CreateRow(i, page, Pname, group); } + + TotalRows = group.getButtonCount(); + + JButton displayProfile = new JButton("Display Profile"); + + ActionListener displayer = e -> { + System.out.println("displayer clicked"); + }; + displayProfile.addActionListener(displayer); + + JButton addProfile = new JButton("Add Profile"); + ActionListener adder = e -> { + System.out.println("profile add button clicked"); + }; + addProfile.addActionListener(adder); + + JPanel footer = new JPanel(); + + footer.add(displayProfile); + footer.add(addProfile); + + page.add(footer); } public MainViewer() // main viewer window @@ -179,6 +204,8 @@ public class MainViewer { radioButtons = new ArrayList<>(); + + JTabbedPane JT = new JTabbedPane(); JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("file"); @@ -201,7 +228,7 @@ public class MainViewer { menu.add(save); ActionListener SaveAction = e -> { System.out.println("Save attempt made"); -// UserGroup.SaveFor(JT); + UserGroup.SaveFor(file, viewer, TotalRows); }; save.addActionListener(SaveAction);