Generics to center all types of JFrame children
This commit is contained in:
@@ -5,6 +5,7 @@ import org.lumijiez.enums.StudyField;
|
||||
import org.lumijiez.gui.util.ComboRenderer;
|
||||
import org.lumijiez.gui.util.ComponentDecorator;
|
||||
import org.lumijiez.gui.util.DisplayHandler;
|
||||
import org.lumijiez.gui.util.WindowConfig;
|
||||
import org.lumijiez.managers.Supervisor;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -82,7 +83,6 @@ public class AddFacultyForm extends JFrame {
|
||||
.addGap(0, 0, Short.MAX_VALUE)
|
||||
.addComponent(titleLabel)
|
||||
.addGap(149, 149, 149)));
|
||||
|
||||
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(7, 7, 7)
|
||||
@@ -103,10 +103,7 @@ public class AddFacultyForm extends JFrame {
|
||||
.addComponent(submitButton))
|
||||
.addContainerGap(24, Short.MAX_VALUE)));
|
||||
pack();
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int x = (screenSize.width - this.getWidth()) / 2;
|
||||
int y = (screenSize.height - this.getHeight()) / 2;
|
||||
this.setLocation(x, y);
|
||||
WindowConfig.center(this);
|
||||
}
|
||||
|
||||
private void submitEvent(ActionEvent evt) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.lumijiez.enums.StudyField;
|
||||
import org.lumijiez.gui.util.ComboRenderer;
|
||||
import org.lumijiez.gui.util.ComponentDecorator;
|
||||
import org.lumijiez.gui.util.DisplayHandler;
|
||||
import org.lumijiez.gui.util.WindowConfig;
|
||||
import org.lumijiez.managers.Supervisor;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -114,14 +115,13 @@ public class EditFacultyForm extends JFrame {
|
||||
.addComponent(submitButton))
|
||||
.addGap(14, 14, 14)));
|
||||
pack();
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int x = (screenSize.width - this.getWidth()) / 2;
|
||||
int y = (screenSize.height - this.getHeight()) / 2;
|
||||
this.setLocation(x, y);
|
||||
WindowConfig.center(this);
|
||||
}
|
||||
|
||||
private void facultyComboEvent(ActionEvent actionEvent) {
|
||||
specialtyCombo.setSelectedItem(((Faculty) Objects.requireNonNull(facultyCombo.getSelectedItem())).getField());
|
||||
Faculty fac = ((Faculty) Objects.requireNonNull(facultyCombo.getSelectedItem()));
|
||||
specialtyCombo.setSelectedItem(fac.getField());
|
||||
nameField.setText(fac.getName());
|
||||
}
|
||||
|
||||
private void specialtyComboEvent(ActionEvent actionEvent) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.lumijiez.base.Faculty;
|
||||
import org.lumijiez.gui.util.ComboRenderer;
|
||||
import org.lumijiez.gui.util.ComponentDecorator;
|
||||
import org.lumijiez.gui.util.DisplayHandler;
|
||||
import org.lumijiez.gui.util.WindowConfig;
|
||||
import org.lumijiez.managers.Supervisor;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -76,10 +77,7 @@ public class RemoveFacultyForm extends JFrame {
|
||||
.addComponent(submitButton))
|
||||
.addContainerGap(21, Short.MAX_VALUE)));
|
||||
pack();
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int x = (screenSize.width - this.getWidth()) / 2;
|
||||
int y = (screenSize.height - this.getHeight()) / 2;
|
||||
this.setLocation(x, y);
|
||||
WindowConfig.center(this);
|
||||
}
|
||||
|
||||
private void submitEvent(ActionEvent evt) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.lumijiez.base.Faculty;
|
||||
import org.lumijiez.base.Group;
|
||||
import org.lumijiez.gui.util.ComboRenderer;
|
||||
import org.lumijiez.gui.util.ComponentDecorator;
|
||||
import org.lumijiez.gui.util.WindowConfig;
|
||||
import org.lumijiez.managers.Supervisor;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -79,10 +80,7 @@ public class ShowFacultyForm extends JFrame {
|
||||
.addComponent(submitButton))
|
||||
.addContainerGap(24, Short.MAX_VALUE)));
|
||||
pack();
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int x = (screenSize.width - this.getWidth()) / 2;
|
||||
int y = (screenSize.height - this.getHeight()) / 2;
|
||||
this.setLocation(x, y);
|
||||
WindowConfig.center(this);
|
||||
}
|
||||
|
||||
private void submitEvent(ActionEvent evt) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.lumijiez.base.Faculty;
|
||||
import org.lumijiez.enums.StudyField;
|
||||
import org.lumijiez.gui.util.ComboRenderer;
|
||||
import org.lumijiez.gui.util.ComponentDecorator;
|
||||
import org.lumijiez.gui.util.WindowConfig;
|
||||
import org.lumijiez.managers.Supervisor;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -79,10 +80,7 @@ public class ShowSpecialtyFacultyForm extends JFrame {
|
||||
.addComponent(submitButton))
|
||||
.addContainerGap(24, Short.MAX_VALUE)));
|
||||
pack();
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int x = (screenSize.width - this.getWidth()) / 2;
|
||||
int y = (screenSize.height - this.getHeight()) / 2;
|
||||
this.setLocation(x, y);
|
||||
WindowConfig.center(this);
|
||||
}
|
||||
|
||||
private void submitEvent(ActionEvent evt) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.lumijiez.base.Group;
|
||||
import org.lumijiez.gui.util.ComboRenderer;
|
||||
import org.lumijiez.gui.util.ComponentDecorator;
|
||||
import org.lumijiez.gui.util.DisplayHandler;
|
||||
import org.lumijiez.gui.util.WindowConfig;
|
||||
import org.lumijiez.managers.Supervisor;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -89,10 +90,7 @@ public class AddGroupForm extends JFrame {
|
||||
.addComponent(submitButton))
|
||||
.addGap(15, 15, 15)));
|
||||
pack();
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int x = (screenSize.width - this.getWidth()) / 2;
|
||||
int y = (screenSize.height - this.getHeight()) / 2;
|
||||
this.setLocation(x, y);
|
||||
WindowConfig.center(this);
|
||||
}
|
||||
|
||||
private void submitEvent(ActionEvent evt) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.lumijiez.base.Group;
|
||||
import org.lumijiez.gui.util.ComboRenderer;
|
||||
import org.lumijiez.gui.util.ComponentDecorator;
|
||||
import org.lumijiez.gui.util.DisplayHandler;
|
||||
import org.lumijiez.gui.util.WindowConfig;
|
||||
import org.lumijiez.managers.Supervisor;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -77,10 +78,7 @@ public class DeleteGroupForm extends JFrame {
|
||||
.addComponent(submitButton))
|
||||
.addContainerGap(18, Short.MAX_VALUE)));
|
||||
pack();
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int x = (screenSize.width - this.getWidth()) / 2;
|
||||
int y = (screenSize.height - this.getHeight()) / 2;
|
||||
this.setLocation(x, y);
|
||||
WindowConfig.center(this);
|
||||
}
|
||||
|
||||
private void submitEvent(ActionEvent evt) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.lumijiez.base.Group;
|
||||
import org.lumijiez.gui.util.ComboRenderer;
|
||||
import org.lumijiez.gui.util.ComponentDecorator;
|
||||
import org.lumijiez.gui.util.DisplayHandler;
|
||||
import org.lumijiez.gui.util.WindowConfig;
|
||||
import org.lumijiez.managers.Supervisor;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -103,18 +104,17 @@ public class EditGroupForm extends JFrame {
|
||||
.addComponent(submitButton))
|
||||
.addContainerGap(36, Short.MAX_VALUE)));
|
||||
pack();
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int x = (screenSize.width - this.getWidth()) / 2;
|
||||
int y = (screenSize.height - this.getHeight()) / 2;
|
||||
this.setLocation(x, y);
|
||||
WindowConfig.center(this);
|
||||
}
|
||||
|
||||
private void submitEvent(ActionEvent evt) {
|
||||
Faculty fac = ((Faculty) Objects.requireNonNull(facultyCombo.getSelectedItem()));
|
||||
Group gr = (Group) Objects.requireNonNull(groupCombo.getSelectedItem());
|
||||
sv.editGroup(gr, nameField.getText(), fac);
|
||||
DisplayHandler.displayGroups();
|
||||
this.dispose();
|
||||
if (!nameField.getText().isEmpty()) {
|
||||
sv.editGroup(gr, nameField.getText(), fac);
|
||||
DisplayHandler.displayGroups();
|
||||
this.dispose();
|
||||
} else JOptionPane.showMessageDialog(null, "Fill in all the fields!", "Warning!", JOptionPane.INFORMATION_MESSAGE, null);
|
||||
}
|
||||
|
||||
private void cancelEvent(ActionEvent evt) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.lumijiez.base.Group;
|
||||
import org.lumijiez.base.Student;
|
||||
import org.lumijiez.gui.util.ComboRenderer;
|
||||
import org.lumijiez.gui.util.ComponentDecorator;
|
||||
import org.lumijiez.gui.util.WindowConfig;
|
||||
import org.lumijiez.managers.Supervisor;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -81,10 +82,7 @@ public class ShowGroupForm extends JFrame {
|
||||
.addComponent(submitButton))
|
||||
.addContainerGap(25, Short.MAX_VALUE)));
|
||||
pack();
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int x = (screenSize.width - this.getWidth()) / 2;
|
||||
int y = (screenSize.height - this.getHeight()) / 2;
|
||||
this.setLocation(x, y);
|
||||
WindowConfig.center(this);
|
||||
}
|
||||
|
||||
private void submitEvent(ActionEvent evt) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.lumijiez.base.Group;
|
||||
import org.lumijiez.gui.util.ComboRenderer;
|
||||
import org.lumijiez.gui.util.ComponentDecorator;
|
||||
import org.lumijiez.gui.util.DisplayHandler;
|
||||
import org.lumijiez.gui.util.WindowConfig;
|
||||
import org.lumijiez.managers.Supervisor;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -234,10 +235,7 @@ public class AddStudentForm extends JFrame {
|
||||
.addComponent(submitButton))
|
||||
.addGap(21, 21, 21)));
|
||||
pack();
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int x = (screenSize.width - this.getWidth()) / 2;
|
||||
int y = (screenSize.height - this.getHeight()) / 2;
|
||||
this.setLocation(x, y);
|
||||
WindowConfig.center(this);
|
||||
}
|
||||
|
||||
private void cancelEvent(ActionEvent actionEvent) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.lumijiez.base.Student;
|
||||
import org.lumijiez.gui.util.ComboRenderer;
|
||||
import org.lumijiez.gui.util.ComponentDecorator;
|
||||
import org.lumijiez.gui.util.DisplayHandler;
|
||||
import org.lumijiez.gui.util.WindowConfig;
|
||||
import org.lumijiez.managers.Supervisor;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -78,10 +79,7 @@ public class DeleteStudentForm extends JFrame {
|
||||
.addComponent(cancelButton))
|
||||
.addContainerGap(26, Short.MAX_VALUE)));
|
||||
pack();
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int x = (screenSize.width - this.getWidth()) / 2;
|
||||
int y = (screenSize.height - this.getHeight()) / 2;
|
||||
this.setLocation(x, y);
|
||||
WindowConfig.center(this);
|
||||
}
|
||||
|
||||
private void submitEvent(ActionEvent evt) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.lumijiez.base.Student;
|
||||
import org.lumijiez.gui.util.ComboRenderer;
|
||||
import org.lumijiez.gui.util.ComponentDecorator;
|
||||
import org.lumijiez.gui.util.DisplayHandler;
|
||||
import org.lumijiez.gui.util.WindowConfig;
|
||||
import org.lumijiez.managers.Supervisor;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -243,10 +244,7 @@ public class EditStudentForm extends JFrame {
|
||||
.addComponent(cancelButton))
|
||||
.addContainerGap(25, Short.MAX_VALUE)));
|
||||
pack();
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int x = (screenSize.width - this.getWidth()) / 2;
|
||||
int y = (screenSize.height - this.getHeight()) / 2;
|
||||
this.setLocation(x, y);
|
||||
WindowConfig.center(this);
|
||||
}
|
||||
|
||||
private void cancelEvent(ActionEvent actionEvent) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.lumijiez.base.Student;
|
||||
import org.lumijiez.enums.Subjects;
|
||||
import org.lumijiez.gui.util.ComboRenderer;
|
||||
import org.lumijiez.gui.util.ComponentDecorator;
|
||||
import org.lumijiez.gui.util.WindowConfig;
|
||||
import org.lumijiez.managers.Supervisor;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -109,10 +110,7 @@ public class GradeStudentForm extends JFrame {
|
||||
.addComponent(submitButton))
|
||||
.addContainerGap(30, Short.MAX_VALUE)));
|
||||
pack();
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int x = (screenSize.width - this.getWidth()) / 2;
|
||||
int y = (screenSize.height - this.getHeight()) / 2;
|
||||
this.setLocation(x, y);
|
||||
WindowConfig.center(this);
|
||||
}
|
||||
|
||||
private void submitEvent(ActionEvent evt) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.lumijiez.base.Student;
|
||||
import org.lumijiez.gui.util.ComboRenderer;
|
||||
import org.lumijiez.gui.util.ComponentDecorator;
|
||||
import org.lumijiez.gui.util.DisplayHandler;
|
||||
import org.lumijiez.gui.util.WindowConfig;
|
||||
import org.lumijiez.managers.Supervisor;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -78,10 +79,7 @@ public class GraduateStudentForm extends JFrame {
|
||||
.addComponent(cancelButton))
|
||||
.addContainerGap(26, Short.MAX_VALUE)));
|
||||
pack();
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int x = (screenSize.width - this.getWidth()) / 2;
|
||||
int y = (screenSize.height - this.getHeight()) / 2;
|
||||
this.setLocation(x, y);
|
||||
WindowConfig.center(this);
|
||||
}
|
||||
|
||||
private void cancelEvent(ActionEvent evt) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.lumijiez.gui.forms.student;
|
||||
import org.lumijiez.base.Student;
|
||||
import org.lumijiez.gui.util.ComboRenderer;
|
||||
import org.lumijiez.gui.util.ComponentDecorator;
|
||||
import org.lumijiez.gui.util.WindowConfig;
|
||||
import org.lumijiez.managers.Supervisor;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -81,10 +82,7 @@ public class ShowStudentForm extends JFrame {
|
||||
.addComponent(submitButton))
|
||||
.addContainerGap(22, Short.MAX_VALUE)));
|
||||
pack();
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int x = (screenSize.width - this.getWidth()) / 2;
|
||||
int y = (screenSize.height - this.getHeight()) / 2;
|
||||
this.setLocation(x, y);
|
||||
WindowConfig.center(this);
|
||||
}
|
||||
|
||||
private void submitEvent(ActionEvent evt) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.lumijiez.base.Grade;
|
||||
import org.lumijiez.base.Student;
|
||||
import org.lumijiez.gui.util.ComboRenderer;
|
||||
import org.lumijiez.gui.util.ComponentDecorator;
|
||||
import org.lumijiez.gui.util.WindowConfig;
|
||||
import org.lumijiez.managers.Supervisor;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -82,10 +83,7 @@ public class ShowStudentGradesForm extends JFrame {
|
||||
.addComponent(submitButton))
|
||||
.addContainerGap(22, Short.MAX_VALUE)));
|
||||
pack();
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int x = (screenSize.width - this.getWidth()) / 2;
|
||||
int y = (screenSize.height - this.getHeight()) / 2;
|
||||
this.setLocation(x, y);
|
||||
WindowConfig.center(this);
|
||||
}
|
||||
|
||||
private void submitEvent(ActionEvent evt) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.lumijiez.base.Student;
|
||||
import org.lumijiez.enums.StudyField;
|
||||
import org.lumijiez.gui.util.ComponentDecorator;
|
||||
import org.lumijiez.gui.util.DisplayHandler;
|
||||
import org.lumijiez.gui.util.WindowConfig;
|
||||
import org.lumijiez.managers.Supervisor;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -50,7 +51,6 @@ public class BatchGraduater extends JFrame {
|
||||
formatLabel.setText("File format example:");
|
||||
cancelButton.setText("Cancel");
|
||||
|
||||
|
||||
exampleText.setColumns(15);
|
||||
exampleText.setRows(5);
|
||||
exampleText.setEditable(false);
|
||||
@@ -99,10 +99,7 @@ public class BatchGraduater extends JFrame {
|
||||
.addComponent(submitButton))
|
||||
.addGap(23, 23, 23)));
|
||||
pack();
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int x = (screenSize.width - this.getWidth()) / 2;
|
||||
int y = (screenSize.height - this.getHeight()) / 2;
|
||||
this.setLocation(x, y);
|
||||
WindowConfig.center(this);
|
||||
}
|
||||
|
||||
private void cancelEvent(ActionEvent evt) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.lumijiez.base.Group;
|
||||
import org.lumijiez.enums.StudyField;
|
||||
import org.lumijiez.gui.util.ComponentDecorator;
|
||||
import org.lumijiez.gui.util.DisplayHandler;
|
||||
import org.lumijiez.gui.util.WindowConfig;
|
||||
import org.lumijiez.managers.Supervisor;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -52,7 +53,6 @@ public class BatchLoader extends JFrame {
|
||||
formatLabel.setText("File format example:");
|
||||
cancelButton.setText("Cancel");
|
||||
|
||||
|
||||
exampleText.setColumns(15);
|
||||
exampleText.setRows(5);
|
||||
exampleText.setEditable(false);
|
||||
@@ -101,10 +101,7 @@ public class BatchLoader extends JFrame {
|
||||
.addComponent(submitButton))
|
||||
.addGap(23, 23, 23)));
|
||||
pack();
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int x = (screenSize.width - this.getWidth()) / 2;
|
||||
int y = (screenSize.height - this.getHeight()) / 2;
|
||||
this.setLocation(x, y);
|
||||
WindowConfig.center(this);
|
||||
}
|
||||
|
||||
private void cancelEvent(ActionEvent evt) {
|
||||
|
||||
13
Lab2/src/main/java/org/lumijiez/gui/util/WindowConfig.java
Normal file
13
Lab2/src/main/java/org/lumijiez/gui/util/WindowConfig.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package org.lumijiez.gui.util;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class WindowConfig {
|
||||
public static <T extends JFrame> void center(T frame) {
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int x = (screenSize.width - frame.getWidth()) / 2;
|
||||
int y = (screenSize.height - frame.getHeight()) / 2;
|
||||
frame.setLocation(x, y);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user