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