Created a proper UserGroup class with attributes to get all users from array list so that the populate panel function can go through all users and populate the panels based on the total number of users
This commit is contained in:
1 parent
8245777db1
commit
0b66878649
3 files changed
+21
-7
No files matched your search
@@ -9,7 +9,7 @@ public class User {
|
|||||||
private String address;
|
private String address;
|
||||||
|
|
||||||
|
|
||||||
private String getUserAttribute(User user, String panelName) {
|
public String getUserAttribute(String panelName) {
|
||||||
return switch (panelName.toLowerCase()) {
|
return switch (panelName.toLowerCase()) {
|
||||||
case "title" -> user.getTitle();
|
case "title" -> user.getTitle();
|
||||||
case "name" -> user.getName();
|
case "name" -> user.getName();
|
||||||
|
|||||||
@@ -4,11 +4,25 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public class UserGroup {
|
public class UserGroup {
|
||||||
|
|
||||||
private ArrayList<User> users;
|
private static ArrayList<User> users;
|
||||||
|
|
||||||
public UserGroup()
|
private UserGroup() {
|
||||||
{
|
users = new ArrayList<>();
|
||||||
new ArrayList<User>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
public static ArrayList<User> getUsers() {
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addUser(User user) {
|
||||||
|
users.add(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getUser(int index) {
|
||||||
|
if (index >= 0 && index < users.size()) {
|
||||||
|
return users.get(index);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -66,7 +66,7 @@ public class MainViewer {
|
|||||||
String panelName = panel.getName();
|
String panelName = panel.getName();
|
||||||
|
|
||||||
for (User user : UserGroup.getUsers()) {
|
for (User user : UserGroup.getUsers()) {
|
||||||
JRadioButton radioButton = new JRadioButton(getUserAttribute(user, panelName));
|
JRadioButton radioButton = new JRadioButton(user.getUserAttribute(panelName));
|
||||||
group.add(radioButton);
|
group.add(radioButton);
|
||||||
panel.add(radioButton);
|
panel.add(radioButton);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user