Java Reference
In-Depth Information
// Define a STATIC class method that will print out a line.
public static void printLineWithPosition ( String line,
int linesToSkip, int charsToSkip) {
int i;
// Print out some blank lines.
for (i=0; i != linesToSkip; i++)
System.out.println ();
// Print out some blank characters.
for (i=0; i != charsToSkip; i++)
System.out.print (' ');
// Print out the error message.
System.out.println (line);
}
}
21. Compile this class in the DOS command window:
javac WriteLine.java
22. Edit the PrintfileErrorMsg class so that it uses this new interface definition
and the supporting class. Add these bolded lines of code to the top and to
the bottom of the class and remove the logic that you've placed in Write-
Line . Your PrintfileErrorMsg class should look like this:
//
//
// PrintfileErrorMsg
//
//
class PrintfileErrorMsg extends ErrorMsg
implements WriteLineInterface {
private static int outputLineSize = 80;
public int linesToSkip = 0;
private int charsToSkip = 0;
// Create a version of this variable that hides the one in TextMessage.
public int msgSize;
// Define a setErrorMsg method that establishes the number of
// chars to output in order to center the error msg.
Search WWH ::




Custom Search