W4R2 – Synchronise 'ButtonGroups' -- added a method to do the button selection
This commit is contained in:
1 parent
5e403676af
commit
5493aa2a0a
1 file changed
+22
-10
@@ -4,7 +4,6 @@
|
||||
*/
|
||||
package userprofilebuilder.view;
|
||||
|
||||
import userprofilebuilder.model.User;
|
||||
import userprofilebuilder.model.UserGroup;
|
||||
|
||||
import java.awt.*;
|
||||
@@ -13,7 +12,7 @@ import javax.swing.border.*;
|
||||
import javax.swing.filechooser.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -23,6 +22,7 @@ import java.util.ArrayList;
|
||||
public class MainViewer {
|
||||
public JFrame viewer;
|
||||
public String file = "userprofile.csv";
|
||||
public ArrayList<JRadioButton> radioButtons = new ArrayList<>();
|
||||
|
||||
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,7 +88,7 @@ public class MainViewer {
|
||||
jp.add(RowPanel);
|
||||
|
||||
group.add(JR);
|
||||
RadioGrouper(JR);
|
||||
radioButtons.add(JR);
|
||||
|
||||
System.out.println("Row number: "+ row + " Has been created!");
|
||||
|
||||
@@ -100,6 +100,7 @@ public class MainViewer {
|
||||
|
||||
ActionListener RadioListener = e -> {
|
||||
System.out.println("Radio Button toggled for Row: " + row + "\n- with Radio Button Text as: " + JR.getText() + "\n- With state of radio button changed to: " + JR.isSelected() + "\n- For tab: " + Pname);
|
||||
ButtonSelector(JR.isSelected(), row);
|
||||
};
|
||||
JR.addActionListener(RadioListener);
|
||||
|
||||
@@ -110,12 +111,6 @@ 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){
|
||||
|
||||
@@ -181,6 +176,7 @@ public class MainViewer {
|
||||
viewer.setSize(800,500);
|
||||
viewer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
radioButtons = new ArrayList<>();
|
||||
|
||||
JTabbedPane JT = new JTabbedPane();
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
@@ -229,6 +225,22 @@ public class MainViewer {
|
||||
viewer.setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void ButtonSelector(Boolean j, int row)
|
||||
{
|
||||
JPanel mainPane = (JPanel) viewer.getContentPane();
|
||||
JTabbedPane jt = (JTabbedPane) mainPane.getComponent(0);
|
||||
for (int i=0; i<3; i++) // 3 == the amount of tabs.
|
||||
{
|
||||
JPanel jp1 = (JPanel) jt.getComponentAt(i); // tab
|
||||
JPanel jp2 = (JPanel) jp1.getComponent(row-1); // row
|
||||
JRadioButton jr1 = (JRadioButton) jp2.getComponent(0); // always stays 0 --> selecting radio button
|
||||
jr1.setSelected(j);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user