Skip to content

Commit 5906ef2

Browse files
authored
Update MainApp.java
1 parent 77f2486 commit 5906ef2

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

src/sortvisualiser/MainApp.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,35 @@
77
import javax.swing.SwingUtilities;
88

99
public class MainApp {
10-
private final JFrame window;
10+
private final JFrame window;/*JFrame is a class of the javax.swing package. It provides GUI interface
11+
Frame works like the main window where components like labels, buttons, textfields are added to create a GUI.*/
12+
public static final int WIN_WIDTH = 1280; // Assigning width of main frame window
13+
public static final int WIN_HEIGHT = 720; //Assigning height of main frame window
1114

12-
public static final int WIN_WIDTH = 1280;
13-
public static final int WIN_HEIGHT = 720;
14-
15-
private final ArrayList<Screen> screens;
15+
private final ArrayList<Screen> screens; // created a arraylist of type Screen
1616

1717
public MainApp() {
18-
screens = new ArrayList<>();
19-
window = new JFrame ("Sort visualiser");
20-
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
21-
window.setVisible(true);
18+
screens = new ArrayList<>(); // Initialising a new arraylist of screens
19+
window = new JFrame ("Sort visualiser"); // Heading of GUI window
20+
window.setVisible(true); // For making the GUI visible or not
2221
}
2322

24-
public Screen getCurrentScreen() {
23+
public Screen getCurrentScreen() { //returns current screen
2524
return screens.get(screens.size() - 1);
2625
}
2726

28-
public void pushScreen(Screen screen) {
29-
if (!screens.isEmpty()) {
27+
public void pushScreen(Screen screen) { //initialised a method to push screen that takes object of Screen class as parameter
28+
if (!screens.isEmpty()) { // if screen is not empty then remove the current screen from GUI
3029
window.remove(getCurrentScreen());
3130
}
32-
screens.add(screen);
33-
window.setContentPane(screen);
34-
window.validate();
31+
screens.add(screen); // If screen is empty, add a new screen to GUi
32+
window.setContentPane(screen); // Set the content pane through the screen object
33+
window.validate(); //Inbuilt function
3534
screen.onOpen();
3635
}
3736

38-
public void popScreen() {
39-
if (!screens.isEmpty()) {
37+
public void popScreen() { //initiated a method to pop the window and screen on GUI
38+
if (!screens.isEmpty()) { // if screen is not empty then remove the window and screen
4039
Screen prev = getCurrentScreen();
4140
screens.remove(prev);
4241
window.remove(prev);
@@ -52,15 +51,14 @@ public void popScreen() {
5251
}
5352
}
5453

55-
public void start() {
54+
public void start() { // starts and push the main menu screen onto the GUI
5655
pushScreen(new MainMenuScreen(this));
5756
window.pack();
5857
}
5958

60-
public static void main(String... args) {
61-
System.setProperty("sun.java2d.opengl", "true");
59+
public static void main(String[] args) {
6260
SwingUtilities.invokeLater(() -> {
6361
new MainApp().start();
6462
});
6563
}
66-
}
64+
}

0 commit comments

Comments
 (0)