W4R1 – 'ButtonGroups' for 'JRadioButtons'

This commit is contained in:
bobbert committed 2025-02-15 14:09:31 +00:00
1 parent fed70cf754
commit 5e403676af
2 files changed
+41 -18

No files matched your search

@@ -4,6 +4,7 @@
*/ */
package userprofilebuilder.model; package userprofilebuilder.model;
import javax.swing.*;
import java.io.*; import java.io.*;
@@ -13,7 +14,7 @@ import java.io.*;
* This is model class may be handy for putting data relevant groups of User Profiles in {many Users] * This is model class may be handy for putting data relevant groups of User Profiles in {many Users]
*/ */
public class UserGroup { public class UserGroup {
public String getUser(int row, String Pname, String file) { public static String getUser(int row, String Pname, String file) {
String text = "Default Text"; String text = "Default Text";
String[] values = null; String[] values = null;
try (BufferedReader csvReader = new BufferedReader(new FileReader(file))) { try (BufferedReader csvReader = new BufferedReader(new FileReader(file))) {
@@ -51,4 +52,21 @@ public class UserGroup {
return text; return text;
} }
public static void SaveFor(JTabbedPane jt, String file)
{
String[] values = null;
try (BufferedReader csvReader = new BufferedReader(new FileReader(file))) {
while (csvReader.ready()) {
String line = csvReader.readLine();
values = line.split(",");
}
}
catch (Exception e) {
System.out.println("error with reader");
}
}
} }
@@ -4,6 +4,7 @@
*/ */
package userprofilebuilder.view; package userprofilebuilder.view;
import userprofilebuilder.model.User;
import userprofilebuilder.model.UserGroup; import userprofilebuilder.model.UserGroup;
import java.awt.*; import java.awt.*;
@@ -12,6 +13,7 @@ import javax.swing.border.*;
import javax.swing.filechooser.*; import javax.swing.filechooser.*;
import java.awt.event.*; import java.awt.event.*;
import java.io.*; import java.io.*;
import java.util.ArrayList;
/** /**
* *
@@ -62,34 +64,31 @@ public class MainViewer {
return text; return text;
} }
private void CreateRow(int count, JPanel jp, String Pname) private void CreateRow(int count, JPanel jp, String Pname, ButtonGroup group)
{ {
int row = count+1; int row = count+1;
String name = Reader(row, Pname); JPanel RowPanel = new JPanel();
JPanel minipanel = new JPanel(); JRadioButton JR = new JRadioButton(UserGroup.getUser(row, Pname, file));
JRadioButton JR = new JRadioButton(name);
JButton JEdit = new JButton("Edit"); JButton JEdit = new JButton("Edit");
JButton JDelete = new JButton("Delete"); JButton JDelete = new JButton("Delete");
// setting the border title to the correct title // setting the border title to the correct title
TitledBorder rowtitle; TitledBorder RowTitle;
rowtitle = BorderFactory.createTitledBorder("User "+ row); RowTitle = BorderFactory.createTitledBorder("User "+ row);
minipanel.setBorder(rowtitle); RowPanel.setBorder(RowTitle);
// end of border title code // end of border title code
minipanel.add(JR); RowPanel.add(JR);
minipanel.add(JEdit); RowPanel.add(JEdit);
minipanel.add(JDelete); RowPanel.add(JDelete);
jp.add(minipanel); jp.add(RowPanel);
ButtonGroup group = new ButtonGroup();
group.add(JR); group.add(JR);
RadioGrouper(JR);
System.out.println("Row number: "+ row + " Has been created!"); System.out.println("Row number: "+ row + " Has been created!");
@@ -111,6 +110,12 @@ public class MainViewer {
} }
public void RadioGrouper(JRadioButton JR)
{
ArrayList<JRadioButton> radioButtons = new ArrayList<>();
radioButtons.add(JR);
}
public void DialogueBox(String JRtext, JRadioButton JR, int row, String Pname){ public void DialogueBox(String JRtext, JRadioButton JR, int row, String Pname){
@@ -148,7 +153,7 @@ public class MainViewer {
public void TabMaker(String Pname, JTabbedPane JT) public void TabMaker(String Pname, JTabbedPane JT)
{ {
ButtonGroup group = new ButtonGroup();
JPanel page = new JPanel(); 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 page.setLayout(new GridLayout(0,1)); // Because i cant remember the orientation of grid layout params it's (x,y) AKA rows , columns
@@ -165,7 +170,7 @@ public class MainViewer {
for (int i=0; i<a; i++) for (int i=0; i<a; i++)
{ {
CreateRow(i, page, Pname); CreateRow(i, page, Pname, group);
} }
} }
@@ -199,6 +204,7 @@ public class MainViewer {
menu.add(save); menu.add(save);
ActionListener SaveAction = e -> { ActionListener SaveAction = e -> {
System.out.println("Save attempt made"); System.out.println("Save attempt made");
// UserGroup.SaveFor(JT);
}; };
save.addActionListener(SaveAction); save.addActionListener(SaveAction);
@@ -225,5 +231,4 @@ public class MainViewer {
} }
} }