fixed issue so that UserGroup stays as a singleton instance so that all users are stored in it properly
This commit is contained in:
1 parent
eb233f43f9
commit
1ea89164f4
2 files changed
+17
-6
No files matched your search
@@ -4,14 +4,21 @@ import java.util.ArrayList;
|
||||
|
||||
public class UserGroup {
|
||||
|
||||
private static ArrayList<User> users;
|
||||
private static UserGroup instance;
|
||||
private ArrayList<User> users;
|
||||
|
||||
private UserGroup() {
|
||||
users = new ArrayList<>();
|
||||
}
|
||||
|
||||
public static UserGroup getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new UserGroup();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static ArrayList<User> getUsers() {
|
||||
public ArrayList<User> getUsers() {
|
||||
return users;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,13 @@ import cvbuilder.model.UserGroup;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
|
||||
public class MainViewer {
|
||||
|
||||
private UserGroup userGroup;
|
||||
|
||||
public MainViewer() {
|
||||
userGroup = UserGroup.getInstance();
|
||||
|
||||
JFrame viewer = new JFrame("CV Builder");
|
||||
viewer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
viewer.setSize(800, 500);
|
||||
@@ -65,13 +68,14 @@ public class MainViewer {
|
||||
ButtonGroup group = new ButtonGroup();
|
||||
String panelName = panel.getName();
|
||||
|
||||
for (User user : UserGroup.getUsers()) {
|
||||
for (User user : userGroup.getUsers()) {
|
||||
JRadioButton radioButton = new JRadioButton(user.getUserAttribute(panelName));
|
||||
group.add(radioButton);
|
||||
panel.add(radioButton);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(MainViewer::new);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user