Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public class FreeSpaceFrame extends JFrame f public FreeSpaceFrame ) super (\"Di

ID: 3703830 • Letter: P

Question

public class FreeSpaceFrame extends JFrame f public FreeSpaceFrame ) super ("Disk Free Space") setLookAndFeel); setsize(500, 120) setDefaultCloseoperation (JFrame.EXIT ON_CLOSE); FlowLayout flo new FlowLayout(); setLayout (flo); FreeSpacePanel freePanelnew FreeSpacePanel) add(freePanel); setvisible(true) private void setLookAndFeel) try f UIManager.SetLookAndFeel( "javax.swing.plaf.nimbus.nimbusLookAndFeel" ) catch (Exception exc) // ignore error public static void main(String arguments) FreeSpaceFrame framenew FreeSpaceFrame)i Disk Free Space Disk Space: 510513745920 free out of 1000240963584 (51.03%)

Explanation / Answer

1. super("Disk Free Space")

This calls the Constructor of JFrame class with title argument that sets the title of the Frame

2. setLookAndFeel()

This calls the private method of the FreeSpaceFrame class which internally set a Look and feel for the frame

3. setSize(500, 120)

This calls to JFrame method setSize that sets the provided width and height of the JFrame

4. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)

This calls to JFrame method setDefaultCloseOpration thats sets the operation to perform on clicking the close (X) icon. JFrame.EXIT_ON_CLOSE means to exit the frame on clicking X

5. FlowLayout flo = new FlowLayout()

setLayout(fo)

Layout helps you to organize UI compoenents on a Frame. One such Layout is Flow Layout which is default layout which adds them in one direction (left to right) or (right to left)

6. FreeSpacePanel freePanel = new FreeSpacePanel()

add(freePanel)

FreeSpacePanel is a JPanel instance and its added to frame using add method of JFrame.

Panel is added on a Frame to allow adding one or more coponents. It as a container and can have its own layout.

7. setVisible(true)

On creation of a Frame it isnt visible be default to make it visible setVisible of JFrame is called with value as true