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

Lab 5.2 — A Window Class (Window) Code the following Window class: The (abstract

ID: 3713502 • Letter: L

Question

Lab 5.2 — A Window Class (Window)

Code the following Window class:

The (abstract) Window class represents a window with a height and width, as well as the status of the window: normal (also known as 'restored') or minimized. In minimized mode, the window's toString result is displayed in a 1-line collapsed fashion (reminiscent of minimizing a window to the task bar):

while displaying the window in 'normal' (or 'restored') depends on the type of window, and thus is deferred to the subclasses (by making it an abstract method ofWindow). Specification:

maintains height and width, and whether the window is minimized

has a display method that displays the window in either normal or minimized mode.

if the window is not visible (regardless of minimized more), the string (Nothing to see here) is displayed

in minimized mode, the display is single line consisting of the toString result for the object, followed by '(minimized)' and surrounded by '[]'s (see below).

has setVisible and isVisible methods

has an abstract displayNormal method.

This will be overridden by your classes in the 5.3 and 5.4, and is being overridden in this exercise by MinWindow

has a resize method that accepts a width and height and sets the window's width and height to those values.

has getHeight and getWidth methods

has minimize and restore methods

I've provided an application class, WindowApp, for testing your class, and, as discussed above, a MinWindow class that provides a minimal implementation of a displayNormal method. THis minimal window class has a self-describing toString that also contains the width and height.

Sample Test Run

For example if the file window.data contains:

the provided WindowApp application class (using the MinWindow) class produces the following output:

Submitting to CodeLab

Please remove public from your Window class header.

In Codelab I will be providing the application and minimal classes. Please submit just the code for the Window interface.

Explanation / Answer

please go through the code throughly and try to understand the logic.

import java.io.*;

import java.util.*;

class WindowApp {

public static void main(String [] args) throws Exception {

//Creating a 5x10 minimal window

MinWindow minWindow = new MinWindow(5, 10);

Window window = minWindow;

//Displaying

window.display();

System.out.println();

//Setting visible to true and displaying

window.setVisible(true);

window.display();

System.out.println();

//Minimizing and displaying

window.minimize();

window.display();

System.out.println();

//Restoring and displaying

window.restore();

window.display();

System.out.println();

//Resizing to 10x5 and displaying

window.resize(window.getHeight(), window.getWidth());

window.display();

System.out.println();

//Minimizing and displaying

window.minimize();

window.display();

System.out.println();

//Creating a window from file data and displaying

Scanner scanner = new Scanner(new File("create_window.data"));

window = MinWindow.read(scanner);

window.display();

System.out.println();

//Setting visible to true and displaying

window.setVisible(true);

window.display();

System.out.println();

//Minimizing and displaying

window.minimize();

window.display();

System.out.println();

}

}

**********

***********

import java.awt.Window;

import java.util.*;

class MinWindow extends Window {

MinWindow(int width, int height) {super(width, height);}

public void displayNormal() {

String s = this+"";

String border = "";

for (int i = 0; i < s.length()+2; i++)

border += ".";

System.out.println(border + " " + ":" + s + ": " + border);

}

public static MinWindow read(Scanner scanner) {

int width = scanner.nextInt();

int height = scanner.nextInt();

return new MinWindow(width, height);

}

public String toString() {return "width of the window " + getWidth() + "Height of the window" + getHeight() + " minimal window";}

}