Implemented UI, fixed serialization inconsistency
This commit is contained in:
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
|
||||
124
.idea/uiDesigner.xml
generated
Normal file
124
.idea/uiDesigner.xml
generated
Normal file
@@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
||||
@@ -1,59 +1,12 @@
|
||||
package org.lumijiez;
|
||||
|
||||
import org.lumijiez.base.Grade;
|
||||
import org.lumijiez.base.NameSurnameGroup;
|
||||
import org.lumijiez.data.DataDeserializer;
|
||||
import org.lumijiez.data.DataSerializer;
|
||||
import org.lumijiez.managers.Manager;
|
||||
import org.lumijiez.gui.StudentManagementGUI;
|
||||
|
||||
import java.util.Scanner;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Main {
|
||||
public static NameSurnameGroup readNSG() {
|
||||
String name = sc.nextLine();
|
||||
String surname = sc.nextLine();
|
||||
String group = sc.nextLine();
|
||||
return new NameSurnameGroup(name, surname, group);
|
||||
}
|
||||
public static Scanner sc = new Scanner(System.in);
|
||||
|
||||
public static void main(String[] args) {
|
||||
Manager studentManager = DataDeserializer.deserialize();
|
||||
|
||||
boolean exit = false;
|
||||
while (!exit) {
|
||||
System.out.println("===== Student Management System =====");
|
||||
System.out.println("1. Show Students");
|
||||
System.out.println("2. Show Groups");
|
||||
System.out.println("3. Show Grades of a Student");
|
||||
System.out.println("4. Add Grade to Student");
|
||||
System.out.println("5. Add Student");
|
||||
System.out.println("6. Remove student");
|
||||
System.out.println("7. Exit and save");
|
||||
System.out.print("Enter your choice: ");
|
||||
|
||||
int choice = sc.nextInt();
|
||||
sc.nextLine();
|
||||
|
||||
switch (choice) {
|
||||
case 1 -> studentManager.printStudents();
|
||||
case 2 -> studentManager.printGroups();
|
||||
case 3 -> studentManager.printGrades(readNSG());
|
||||
case 4 -> studentManager.addGrade(readNSG(), new Grade(sc.nextLine(), sc.nextInt()));
|
||||
case 5 -> studentManager.addStudent(readNSG());
|
||||
case 6 -> studentManager.removeStudent(readNSG());
|
||||
case 7 -> {
|
||||
DataSerializer.serialize(studentManager);
|
||||
exit = true;
|
||||
}
|
||||
default -> System.out.println("Invalid choice. Please try again.");
|
||||
}
|
||||
|
||||
if (!exit) {
|
||||
System.out.println("Press Enter to continue...");
|
||||
sc.nextLine();
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Goodbye!");
|
||||
SwingUtilities.invokeLater(StudentManagementGUI::new);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
package org.lumijiez.gui;
|
||||
|
||||
import org.lumijiez.data.DataDeserializer;
|
||||
import org.lumijiez.data.DataSerializer;
|
||||
import org.lumijiez.gui.forms.*;
|
||||
import org.lumijiez.managers.Manager;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
public class StudentManagementGUI{
|
||||
private final Manager studentManager;
|
||||
private final JFrame frame;
|
||||
private final JTextArea outputTextArea;
|
||||
|
||||
public StudentManagementGUI() {
|
||||
studentManager = DataDeserializer.deserialize();
|
||||
|
||||
frame = new JFrame("Student Management System");
|
||||
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
frame.setSize(800, 600);
|
||||
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int centerX = (int) ((screenSize.getWidth() - frame.getWidth()) / 2);
|
||||
int centerY = (int) ((screenSize.getHeight() - frame.getHeight()) / 2);
|
||||
frame.setLocation(centerX, centerY);
|
||||
|
||||
|
||||
JPanel mainPanel = new JPanel();
|
||||
mainPanel.setLayout(new BorderLayout());
|
||||
|
||||
outputTextArea = new JTextArea();
|
||||
outputTextArea.setEditable(false);
|
||||
outputTextArea.setText("===== Students =====\n" + studentManager.getStudentsText());
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane(outputTextArea);
|
||||
|
||||
mainPanel.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
JPanel buttonPanel = new JPanel(new GridLayout(0, 1));
|
||||
|
||||
JButton showStudentsBtn = new JButton("Show Students");
|
||||
JButton showGroupsBtn = new JButton("Show Groups");
|
||||
JButton changeStudentGroup = new JButton("Change group");
|
||||
JButton addStudentBtn = new JButton("Add Student");
|
||||
JButton addStudentGrade = new JButton("Add Grade");
|
||||
JButton deleteStudentBtn = new JButton("Delete Student");
|
||||
JButton showStudentGradesBtn = new JButton("Show Student Grades");
|
||||
JButton saveAndExitBtn = new JButton("Save and Exit");
|
||||
|
||||
|
||||
showStudentsBtn.addActionListener(e -> outputTextArea.setText("===== Students =====\n" + studentManager.getStudentsText()));
|
||||
|
||||
showGroupsBtn.addActionListener(e -> outputTextArea.setText("===== Groups =====\n" + studentManager.getGroupsText()));
|
||||
|
||||
addStudentBtn.addActionListener(e -> new AddStudentForm(centerX, centerY, studentManager, outputTextArea));
|
||||
|
||||
changeStudentGroup.addActionListener(e -> new ChangeGroupForm(centerX, centerY, studentManager, outputTextArea));
|
||||
|
||||
showStudentGradesBtn.addActionListener(e -> new ShowGradesForm(centerX, centerY, studentManager, outputTextArea));
|
||||
|
||||
deleteStudentBtn.addActionListener(e -> new DeleteStudentForm(centerX, centerY, studentManager, outputTextArea));
|
||||
|
||||
addStudentGrade.addActionListener(e -> new AddGradeForm(centerX, centerY, studentManager, outputTextArea));
|
||||
|
||||
|
||||
saveAndExitBtn.addActionListener(e -> {
|
||||
DataSerializer.serialize(studentManager);
|
||||
frame.dispose();
|
||||
System.exit(0);
|
||||
});
|
||||
|
||||
buttonPanel.add(showStudentsBtn);
|
||||
buttonPanel.add(showGroupsBtn);
|
||||
buttonPanel.add(showStudentGradesBtn);
|
||||
buttonPanel.add(addStudentBtn);
|
||||
buttonPanel.add(addStudentGrade);
|
||||
buttonPanel.add(deleteStudentBtn);
|
||||
buttonPanel.add(saveAndExitBtn);
|
||||
|
||||
mainPanel.add(buttonPanel, BorderLayout.WEST);
|
||||
|
||||
frame.getContentPane().add(mainPanel);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
||||
60
Lab2/src/main/java/org/lumijiez/gui/forms/AddGradeForm.java
Normal file
60
Lab2/src/main/java/org/lumijiez/gui/forms/AddGradeForm.java
Normal file
@@ -0,0 +1,60 @@
|
||||
package org.lumijiez.gui.forms;
|
||||
|
||||
import org.lumijiez.base.Grade;
|
||||
import org.lumijiez.base.NameSurnameGroup;
|
||||
import org.lumijiez.managers.Manager;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class AddGradeForm extends JFrame {
|
||||
public AddGradeForm(int centerX, int centerY, Manager studentManager, JTextArea outputTextArea) {
|
||||
this.setTitle("Add Grade");
|
||||
this.setSize(400, 300);
|
||||
this.setLocation(centerX, centerY);
|
||||
|
||||
JPanel formPanel = new JPanel(new GridLayout(4, 2));
|
||||
|
||||
JLabel nameLabel = new JLabel("Name:");
|
||||
JTextField nameField = new JTextField();
|
||||
JLabel surnameLabel = new JLabel("Surname:");
|
||||
JTextField surnameField = new JTextField();
|
||||
JLabel groupLabel = new JLabel("Group:");
|
||||
JTextField groupField = new JTextField();
|
||||
JLabel subjectLabel = new JLabel("Subject:");
|
||||
JTextField subjectField = new JTextField();
|
||||
JLabel gradeLabel = new JLabel("Grade:");
|
||||
JTextField gradeField = new JTextField();
|
||||
|
||||
JButton submitButton = new JButton("Submit");
|
||||
|
||||
formPanel.add(nameLabel);
|
||||
formPanel.add(nameField);
|
||||
formPanel.add(surnameLabel);
|
||||
formPanel.add(surnameField);
|
||||
formPanel.add(groupLabel);
|
||||
formPanel.add(groupField);
|
||||
formPanel.add(subjectLabel);
|
||||
formPanel.add(subjectField);
|
||||
formPanel.add(gradeLabel);
|
||||
formPanel.add(gradeField);
|
||||
formPanel.add(submitButton);
|
||||
|
||||
this.add(formPanel);
|
||||
|
||||
submitButton.addActionListener(e -> {
|
||||
String name = nameField.getText();
|
||||
String surname = surnameField.getText();
|
||||
String group = groupField.getText();
|
||||
String subject = subjectField.getText();
|
||||
String grade = gradeField.getText();
|
||||
|
||||
if (!name.isEmpty() && !surname.isEmpty() && !group.isEmpty() && !subject.isEmpty() && !grade.isEmpty()) {
|
||||
studentManager.addGrade(new NameSurnameGroup(name, surname, group), new Grade(subject, Integer.parseInt(grade)));
|
||||
outputTextArea.setText("===== Students =====\n" + studentManager.getStudentsText());
|
||||
this.dispose();
|
||||
} else JOptionPane.showMessageDialog(this, "Please fill in all fields.");
|
||||
});
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.lumijiez.gui.forms;
|
||||
|
||||
import org.lumijiez.base.NameSurnameGroup;
|
||||
import org.lumijiez.managers.Manager;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class AddStudentForm extends JFrame {
|
||||
public AddStudentForm(int centerX, int centerY, Manager studentManager, JTextArea outputTextArea) {
|
||||
this.setTitle("Add Student");
|
||||
this.setSize(400, 300);
|
||||
this.setLocation(centerX, centerY);
|
||||
|
||||
JPanel formPanel = new JPanel(new GridLayout(4, 2));
|
||||
|
||||
JLabel nameLabel = new JLabel("Name:");
|
||||
JTextField nameField = new JTextField();
|
||||
JLabel surnameLabel = new JLabel("Surname:");
|
||||
JTextField surnameField = new JTextField();
|
||||
JLabel groupLabel = new JLabel("Group:");
|
||||
JTextField groupField = new JTextField();
|
||||
JButton submitButton = new JButton("Submit");
|
||||
|
||||
formPanel.add(nameLabel);
|
||||
formPanel.add(nameField);
|
||||
formPanel.add(surnameLabel);
|
||||
formPanel.add(surnameField);
|
||||
formPanel.add(groupLabel);
|
||||
formPanel.add(groupField);
|
||||
formPanel.add(submitButton);
|
||||
|
||||
this.add(formPanel);
|
||||
|
||||
submitButton.addActionListener(e -> {
|
||||
String name = nameField.getText();
|
||||
String surname = surnameField.getText();
|
||||
String group = groupField.getText();
|
||||
if (!name.isEmpty() && !surname.isEmpty() && !group.isEmpty()) {
|
||||
studentManager.addStudent(new NameSurnameGroup(name, surname, group));
|
||||
outputTextArea.setText("===== Students =====\n" + studentManager.getStudentsText());
|
||||
this.dispose();
|
||||
} else JOptionPane.showMessageDialog(this, "Please fill in all fields.");
|
||||
});
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package org.lumijiez.gui.forms;
|
||||
|
||||
import org.lumijiez.base.NameSurnameGroup;
|
||||
import org.lumijiez.managers.Manager;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class ChangeGroupForm extends JFrame {
|
||||
public ChangeGroupForm(int centerX, int centerY, Manager studentManager, JTextArea outputTextArea) {
|
||||
this.setTitle("Change Group");
|
||||
this.setSize(400, 300);
|
||||
this.setLocation(centerX, centerY);
|
||||
|
||||
JPanel formPanel = new JPanel(new GridLayout(4, 2));
|
||||
|
||||
JLabel nameLabel = new JLabel("Name:");
|
||||
JTextField nameField = new JTextField();
|
||||
JLabel surnameLabel = new JLabel("Surname:");
|
||||
JTextField surnameField = new JTextField();
|
||||
JLabel groupLabel = new JLabel("Group:");
|
||||
JTextField groupField = new JTextField();
|
||||
JLabel newgroupLabel = new JLabel("New Group:");
|
||||
JTextField newgroupField = new JTextField();
|
||||
JButton submitButton = new JButton("Submit");
|
||||
|
||||
formPanel.add(nameLabel);
|
||||
formPanel.add(nameField);
|
||||
formPanel.add(surnameLabel);
|
||||
formPanel.add(surnameField);
|
||||
formPanel.add(groupLabel);
|
||||
formPanel.add(groupField);
|
||||
formPanel.add(newgroupLabel);
|
||||
formPanel.add(newgroupField);
|
||||
formPanel.add(submitButton);
|
||||
|
||||
this.add(formPanel);
|
||||
|
||||
submitButton.addActionListener(e -> {
|
||||
String name = nameField.getText();
|
||||
String surname = surnameField.getText();
|
||||
String group = groupField.getText();
|
||||
String newgroup = newgroupField.getText();
|
||||
if (!name.isEmpty() && !surname.isEmpty() && !group.isEmpty() && !newgroup.isEmpty()) {
|
||||
studentManager.changeGroup(new NameSurnameGroup(name, surname, group), newgroup);
|
||||
outputTextArea.setText("===== Groups =====\n" + studentManager.getGroupsText());
|
||||
this.dispose();
|
||||
} else JOptionPane.showMessageDialog(this, "Please fill in all fields.");
|
||||
});
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package org.lumijiez.gui.forms;
|
||||
|
||||
import org.lumijiez.base.NameSurnameGroup;
|
||||
import org.lumijiez.managers.Manager;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class DeleteStudentForm extends JFrame {
|
||||
public DeleteStudentForm(int centerX, int centerY, Manager studentManager, JTextArea outputTextArea) {
|
||||
this.setTitle("Delete Student");
|
||||
this.setSize(400, 300);
|
||||
this.setLocation(centerX, centerY);
|
||||
|
||||
JPanel formPanel = new JPanel(new GridLayout(4, 2));
|
||||
|
||||
JLabel nameLabel = new JLabel("Name:");
|
||||
JTextField nameField = new JTextField();
|
||||
JLabel surnameLabel = new JLabel("Surname:");
|
||||
JTextField surnameField = new JTextField();
|
||||
JLabel groupLabel = new JLabel("Group:");
|
||||
JTextField groupField = new JTextField();
|
||||
JButton submitButton = new JButton("Submit");
|
||||
|
||||
formPanel.add(nameLabel);
|
||||
formPanel.add(nameField);
|
||||
formPanel.add(surnameLabel);
|
||||
formPanel.add(surnameField);
|
||||
formPanel.add(groupLabel);
|
||||
formPanel.add(groupField);
|
||||
formPanel.add(submitButton);
|
||||
|
||||
this.add(formPanel);
|
||||
|
||||
submitButton.addActionListener(e -> {
|
||||
String name = nameField.getText();
|
||||
String surname = surnameField.getText();
|
||||
String group = groupField.getText();
|
||||
if (!name.isEmpty() && !surname.isEmpty() && !group.isEmpty()) {
|
||||
studentManager.removeStudent(new NameSurnameGroup(name, surname, group));
|
||||
outputTextArea.setText("===== Students =====\n" + studentManager.getStudentsText());
|
||||
this.dispose();
|
||||
} else JOptionPane.showMessageDialog(this, "Please fill in all fields.");
|
||||
});
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.lumijiez.gui.forms;
|
||||
|
||||
import org.lumijiez.base.NameSurnameGroup;
|
||||
import org.lumijiez.managers.Manager;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class ShowGradesForm extends JFrame {
|
||||
public ShowGradesForm(int centerX, int centerY, Manager studentManager, JTextArea outputTextArea) {
|
||||
this.setTitle("Show Grades Student");
|
||||
this.setSize(400, 300);
|
||||
this.setLocation(centerX, centerY);
|
||||
|
||||
JPanel formPanel = new JPanel(new GridLayout(4, 2));
|
||||
|
||||
JLabel nameLabel = new JLabel("Name:");
|
||||
JTextField nameField = new JTextField();
|
||||
JLabel surnameLabel = new JLabel("Surname:");
|
||||
JTextField surnameField = new JTextField();
|
||||
JLabel groupLabel = new JLabel("Group:");
|
||||
JTextField groupField = new JTextField();
|
||||
JButton submitButton = new JButton("Submit");
|
||||
|
||||
formPanel.add(nameLabel);
|
||||
formPanel.add(nameField);
|
||||
formPanel.add(surnameLabel);
|
||||
formPanel.add(surnameField);
|
||||
formPanel.add(groupLabel);
|
||||
formPanel.add(groupField);
|
||||
formPanel.add(submitButton);
|
||||
|
||||
this.add(formPanel);
|
||||
|
||||
submitButton.addActionListener(e -> {
|
||||
String name = nameField.getText();
|
||||
String surname = surnameField.getText();
|
||||
String group = groupField.getText();
|
||||
if (!name.isEmpty() && !surname.isEmpty() && !group.isEmpty()) {
|
||||
NameSurnameGroup nsg = new NameSurnameGroup(name, surname, group);
|
||||
outputTextArea.setText("===== Grades =====\n" + name + " " + surname + "\n" + studentManager.getGradesText(nsg));
|
||||
this.dispose();
|
||||
} else JOptionPane.showMessageDialog(this, "Please fill in all fields.");
|
||||
});
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
@@ -10,26 +10,23 @@ public class GroupManager implements Serializable {
|
||||
private final List<Group> groups = new ArrayList<>();
|
||||
|
||||
public Group getGroup(String groupName) {
|
||||
for (Group group : groups) {
|
||||
if (group.getName().equals(groupName)) {
|
||||
return group;
|
||||
}
|
||||
}
|
||||
for (Group group : groups)
|
||||
if (group.getName().equals(groupName)) return group;
|
||||
Group newGroup = new Group(groupName);
|
||||
groups.add(newGroup);
|
||||
return newGroup;
|
||||
}
|
||||
|
||||
public void addGroup(Group group) {
|
||||
groups.add(group);
|
||||
}
|
||||
// public void addGroup(Group group) {
|
||||
// groups.add(group);
|
||||
// }
|
||||
|
||||
public List<Group> getGroups() {
|
||||
return groups;
|
||||
}
|
||||
|
||||
public void deleteGroup(Group group) {
|
||||
groups.remove(group);
|
||||
}
|
||||
// public void deleteGroup(Group group) {
|
||||
// groups.remove(group);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -8,41 +8,84 @@ import org.lumijiez.base.Student;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Manager implements Serializable {
|
||||
GroupManager groupManager;
|
||||
private final GroupManager groupManager;
|
||||
|
||||
public Manager() {
|
||||
this.groupManager = new GroupManager();
|
||||
}
|
||||
|
||||
public void addGroup(String groupName) {
|
||||
groupManager.addGroup(new Group(groupName));
|
||||
public String getStudentsText() {
|
||||
StringBuilder info = new StringBuilder();
|
||||
for (Group group : groupManager.getGroups()) {
|
||||
for (Student student : group.getStudents()) {
|
||||
info.append(student.getFullname()).append(" ").append(student.getGroup().getName()).append("\n");
|
||||
}
|
||||
}
|
||||
return info.toString();
|
||||
}
|
||||
|
||||
public String getGradesText(NameSurnameGroup NSG) {
|
||||
StringBuilder info = new StringBuilder();
|
||||
for (Grade grade : groupManager.getGroup(NSG.group()).getStudent(NSG.name(), NSG.surname()).getGrades()) {
|
||||
info.append(grade.getSubject()).append(" ").append(grade.getGrade());
|
||||
}
|
||||
return info.toString();
|
||||
}
|
||||
|
||||
public String getGroupsText() {
|
||||
StringBuilder info = new StringBuilder();
|
||||
for (Group group : groupManager.getGroups()) {
|
||||
info.append(group.getName()).append("\n");
|
||||
}
|
||||
return info.toString();
|
||||
}
|
||||
|
||||
// public Student getStudent(NameSurnameGroup NSG) {
|
||||
// return groupManager.getGroup(NSG.group()).getStudent(NSG.name(), NSG.surname());
|
||||
// }
|
||||
|
||||
public void changeGroup(NameSurnameGroup NSG, String groupName) {
|
||||
Group gr = groupManager.getGroup(groupName);
|
||||
groupManager.getGroup(groupName).getStudent(NSG.name(), NSG.surname()).setGroup(gr);
|
||||
}
|
||||
|
||||
// public void addGroup(String groupName) {
|
||||
// groupManager.addGroup(new Group(groupName));
|
||||
// }
|
||||
|
||||
// public void removeGroup(String groupName) {
|
||||
// groupManager.deleteGroup(groupManager.getGroup(groupName));
|
||||
// }
|
||||
|
||||
// public GroupManager getGroupManager() {
|
||||
// return groupManager;
|
||||
// }
|
||||
|
||||
public void addStudent(NameSurnameGroup NSG) {
|
||||
Group currentGroup = groupManager.getGroup(NSG.group());
|
||||
currentGroup.addStudent(new Student(NSG.name(), NSG.surname(), currentGroup));
|
||||
}
|
||||
|
||||
public void printStudents() {
|
||||
for (Group group : groupManager.getGroups()) {
|
||||
for (Student student : group.getStudents()) {
|
||||
System.out.println(student.getFullname() + " " + student.getGroup().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
// public void printStudents() {
|
||||
// for (Group group : groupManager.getGroups()) {
|
||||
// for (Student student : group.getStudents()) {
|
||||
// System.out.println(student.getFullname() + " " + student.getGroup().getName());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
public void printGroups() {
|
||||
for (Group group : groupManager.getGroups()) {
|
||||
System.out.println(group.getName());
|
||||
}
|
||||
}
|
||||
// public void printGroups() {
|
||||
// for (Group group : groupManager.getGroups()) {
|
||||
// System.out.println(group.getName());
|
||||
// }
|
||||
// }
|
||||
|
||||
public void printGrades(NameSurnameGroup NSG) {
|
||||
Student student = groupManager.getGroup(NSG.group()).getStudent(NSG.name(), NSG.surname());
|
||||
for (Grade grade : student.getGrades()) {
|
||||
System.out.println(grade.getSubject() + " " + grade.getGrade());
|
||||
}
|
||||
}
|
||||
// public void printGrades(NameSurnameGroup NSG) {
|
||||
// Student student = groupManager.getGroup(NSG.group()).getStudent(NSG.name(), NSG.surname());
|
||||
// for (Grade grade : student.getGrades()) {
|
||||
// System.out.println(grade.getSubject() + " " + grade.getGrade());
|
||||
// }
|
||||
// }
|
||||
|
||||
public void addGrade(NameSurnameGroup NSG, Grade grade) {
|
||||
Student student = groupManager.getGroup(NSG.group()).getStudent(NSG.name(), NSG.surname());
|
||||
|
||||
Reference in New Issue
Block a user