Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question

please remove break to exit the loop. Find another way to exit loops without using breaks in the WindowApp class. 

WindowApp class

import java.io.*;
import java.util.Scanner;

class WindowApp{
public static void main(String [] args) {

try {
Window [] window = read();
System.out.println("Creating window data from file data, loading it into an array, and displaying");

for (int i= 0; i < window.length; i++) {
if(window[i] == null) {break;}
System.out.println("--- Window " + i+ ": " + window[i]);
window[i].display();
System.out.println();
}
System.out.println("\nTurning on visibility");
for (int i= 0; i < window.length; i++) {
if(window[i] == null) {break;}
System.out.println("--- Window " + i+ ": " + window[i]);
window[i].setVisible(true);
window[i].displayNormal();
System.out.println();
}
System.out.println("\nResizing (flipping width and height) and displaying");
for (int i= 0; i < window.length; i++) {
if(window[i] == null) {break;}
window[i].resize(window[i].getHeight(), window[i].getWidth());
System.out.println("--- Window " + i+ ": " + window[i]);
window[i].displayNormal();
System.out.println();
}
System.out.println("\nMinimizing and Displaying");
for (int i= 0; i < window.length; i++) {
if(window[i] == null) {break;}
window[i].minimize();
System.out.println("--- Window " + i+ ": " + window[i]);
window[i].display();
}


}
catch(Exception e) { }

}


public static Window[] read() throws Exception{

Window [] window = new Window[25];

Scanner scanner = new Scanner(new File("window.text"));

int size = 0;
while(scanner.hasNext()) {
String typeOfWindow = scanner.next();
if(typeOfWindow.equals("C")){
window[size] = ColoredWindow.read(scanner);
}
else if (typeOfWindow.equals("B")) {
window[size]= BorderedWindow.read(scanner);
}
size++;
}
return window;
}

}

 

 

BorderedWindow

import java.util.Scanner;
class BorderedWindow extends Window {

public BorderedWindow(int width, int height) {
super(width, height);
}

public String toString(){
return "a " + getWidth() + "x" + getHeight()+ " window with a border" ;
}


public void displayNormal() {
String delim = "%" + getWidth() + "s";
String base = "+" + String.format(delim, "").replace(' ', '-') + "+";
String wall= "|" + String.format(delim, "") + "|";
System.out.println(base);
for(int i = 0; i<getHeight(); i++){
System.out.println(wall);
}
System.out.println(base);
}

public static BorderedWindow read(Scanner scanner){
if (!scanner.hasNext()) return null;
int width = scanner.nextInt();
int height = scanner.nextInt();
return new BorderedWindow(width, height);
}

}

ColoredWindow

import java.util.Scanner;
class ColoredWindow extends Window{
private char color = '.';

public ColoredWindow(int width, int height) {
super(width, height);
}

public ColoredWindow(int width, int height, char color) {
super(width, height);
this.color=color;


}

public void setColor(char thisColor){ color= thisColor; }
public char getColor(){ return color; }


public String toString(){
return "a " + getWidth() + "x" + getHeight()+ " window with background color '" + color + "'" ;
}


public void displayNormal() {
int height = getHeight();
while(height > 0){

for(int i=0; i< getWidth(); i++){
System.out.print(color);
}
System.out.println();
height--;
}
}
public static ColoredWindow read(Scanner scanner){
if (!scanner.hasNext()) return null;
int width = scanner.nextInt();
int height = scanner.nextInt();
String stringcolor = scanner.next();
char color = stringcolor.charAt(0);
return new ColoredWindow(width, height, color);
}
}

 

 

Window class

abstract class Window implements GUIComponent {
private int height, width;
private boolean isThisVisible, minimized;

public Window(int width, int height){
this.height = height;
this.width = width;


}

public int getHeight() {
return height; }

public int getWidth() {
return width; }

@Override
public String toString() { return "a " + width + "x" + height + " minimal window"; }


public void display() {
if (!isThisVisible) {
System.out.println("(Nothing to see here)");
}
else if (!minimized) { System.out.println("...........\n:" + toString() + ":\n............");
}

else {
System.out.println("[" + this.toString() + " (minimized)]");
}

}
public void minimize()
{ minimized = true;
}


public void setVisible(boolean isThisVisible) { this.isThisVisible = isThisVisible; }
public boolean isVisible() { return isThisVisible; }
public void restore(){ minimized=false;}


public void resize(int width, int height){
this.width = width;
this.height = height;
}

abstract void displayNormal();


}

 

 

GUIComponent

interface GUIComponent {

void display();
void setVisible(boolean isItvisible);
boolean isVisible();
}

 

 

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY