|
VLine |
|
1 // joi/5/shapes/VLine.java
2 //
3 //
4 // Copyright 2003 Bill Campbell and Ethan Bolker
5
6 /**
7 * A VLine is a vertical Line.
8 */
9
10 public class VLine extends Line
11 {
12 /**
13 * Construct a VLine having a paintChar and a length.
14 *
15 * @param length length in (character) pixels.
16 * @param paintChar character used for painting this Line.
17 */
18
19 public VLine( int length, char paintChar )
20 {
21 super( length, paintChar );
22 }
23
24 /**
25 * Paint this Line on Screen s at position (x,y).
26 *
27 * @param screen the Screen on which this Line is to be painted.
28 * @param x the x position for the line.
29 * @param y the y position for the line.
30 */
31
32 public void paintOn( Screen screen, int x, int y )
33 {
34 for ( int i = 0; i < length; i++ )
35 screen.paintAt( paintChar, x, y+i );
36 }
37
38 /**
39 * Unit test for class VLine.
40 */
41
42 public static void main( String[] argv )
43 {
44 Terminal terminal = new Terminal();
45
46 terminal.println( "Self documenting unit test of VLine.");
47 terminal.println( "The two Screens that follow should match.");
48 terminal.println();
49 terminal.println( "Hard coded picture:");
50 terminal.println( "+++++++++");
51 terminal.println( "+xx +");
52 terminal.println( "+xx +");
53 terminal.println( "+xx +");
54 terminal.println( "+xx * +");
55 terminal.println( "+xx *1 +");
56 terminal.println( "+x * +");
57 terminal.println( "+x * +");
58 terminal.println( "+ * +");
59 terminal.println( "+ +");
60 terminal.println( "+++++++++");
61 terminal.println();
62
63 terminal.println( "Picture drawn using VLine methods:");
64 Screen screen = new Screen( 7, 9 );
65
66 Line vLine = new VLine( 7, 'x' );
67 vLine.paintOn( screen );
68
69 vLine.setLength(5);
70 vLine.paintOn( screen, 1, 0 );
71
72 vLine.setPaintChar('*');
73 vLine.paintOn( screen, 3, 3 );
74
75 vLine.setLength(1);
76 vLine.setPaintChar('1');
77 vLine.paintOn( screen, 4, 4 );
78
79 screen.draw( terminal );
80 }
81
82 }
83
|
VLine |
|