W4R3 – 'UserProfile' Button Panel
This commit is contained in:
1 parent
4ba580a9ee
commit
4b65140f17
2 files changed
+47
-5
No files matched your search
@@ -52,18 +52,33 @@ 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");
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ public class MainViewer {
|
||||
public JFrame viewer;
|
||||
public String file = "userprofile.csv";
|
||||
public ArrayList<JRadioButton> 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);
|
||||
|
||||
|
||||
Reference in new issue
Block a user