7
7
import javax .swing .SwingUtilities ;
8
8
9
9
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
11
14
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
16
16
17
17
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
22
21
}
23
22
24
- public Screen getCurrentScreen () {
23
+ public Screen getCurrentScreen () { //returns current screen
25
24
return screens .get (screens .size () - 1 );
26
25
}
27
26
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
30
29
window .remove (getCurrentScreen ());
31
30
}
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
35
34
screen .onOpen ();
36
35
}
37
36
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
40
39
Screen prev = getCurrentScreen ();
41
40
screens .remove (prev );
42
41
window .remove (prev );
@@ -52,15 +51,14 @@ public void popScreen() {
52
51
}
53
52
}
54
53
55
- public void start () {
54
+ public void start () { // starts and push the main menu screen onto the GUI
56
55
pushScreen (new MainMenuScreen (this ));
57
56
window .pack ();
58
57
}
59
58
60
- public static void main (String ... args ) {
61
- System .setProperty ("sun.java2d.opengl" , "true" );
59
+ public static void main (String [] args ) {
62
60
SwingUtilities .invokeLater (() -> {
63
61
new MainApp ().start ();
64
62
});
65
63
}
66
- }
64
+ }
0 commit comments