KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > samples > document > Document


1 /*
2   Copyright (C) AOPSYS (http://www.aopsys.com)
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License as published by
6   the Free Software Foundation; either version 2 of the License, or
7   (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU General Public License for more details.
13
14   You should have received a copy of the GNU General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */

18
19 package org.objectweb.jac.samples.document;
20
21 /**
22  * A simple document class.
23  */

24
25 public class Document {
26    
27    /** Store the line */
28    public String JavaDoc[] lines;
29
30    /** Creates a document with the given lines */
31    public Document( String JavaDoc[] lines ) {
32       this.lines = lines;
33    }
34
35    /** Print the whole document -- uses printLine() */
36    public void printAll () {
37       for (int i = 0; i < lines.length; i++)
38          printLine( i );
39    }
40
41    /** Print n lines of the document */
42    public void printLines (int startLine, int n) {
43       for (int i = startLine; i < n + startLine; i++)
44          printLine( i );
45    }
46    
47    /** Print a line of the document (can be used directly) */
48    public void printLine (int i) {
49       System.out.println( lines[i] );
50    }
51
52     /** Set a line value */
53     public void setLine( int number, String JavaDoc s ) {
54     lines[number] = s;
55     }
56
57     /** Set a line value */
58     public void setLines( String JavaDoc[] lines ) {
59     this.lines = lines;
60     }
61
62    /** Return the number of lines */
63    public int countLines() {
64       return lines.length;
65    }
66
67    /** Prints out some lines. */
68    public void test() {
69        System.out.println("-- Printing the first line");
70        printLine(0);
71        System.out.println("-- Printing the lines 3 and 4");
72        printLines(2,2);
73        System.out.println("-- Printing all the document");
74        printAll();
75    }
76
77 }
78
79
80
81
82
Popular Tags