/*********************************************************** * Classe per disegnare sullo schermo un rettangolo mediante * caratteri. Poiche` ciascun carattere e` piu` alto che largo * i rettangoli appariranno allungati. Eredita * getOffset, setOffset e drawAt dalla classe Figure. ***********************************************************/ public class Box extends Figure { private int height; private int width; public Box() { super(); height = 0; width = 0; } public Box(int theOffset, int theHeight, int theWidth) { super(theOffset); height = theHeight; width = theWidth; } public void reset(int newOffset, int newHeight, int newWidth) { setOffset(newOffset); height = newHeight; width = newWidth; } /************************************* * Disegna la figura alla riga corrente. * Sovrascrive il metodo ereditato. *************************************/ protected void drawHere() { drawHorizontalLine(); drawSides(); drawHorizontalLine(); } private void drawHorizontalLine() { spaces(getOffset()); int count; for (count = 0; count < width; count++) System.out.print('-'); System.out.println(); } private void drawSides() { int count; for (count = 0; count < (height - 2); count++) drawOneLineOfSides(); } private void drawOneLineOfSides() { spaces(getOffset()); System.out.print('|'); spaces(width - 2); System.out.println('|'); } // Scrive lo specificato numero di caratteri blank. private static void spaces(int number) { int count; for (count = 0; count < number; count++) System.out.print(' '); } public static void main(String[] args) { int indent = 5, amp = 4, alt =5; System.out.println("Test di Box"); Box x = new Box(indent, alt, amp); x.drawAt(1); Box y = new Box (indent,4 , 10); y.drawAt(0); } }