Java Reference
In-Depth Information
public void setErrorMsg (String inputMsg) {
super.setErrorMsg (inputMsg);
charsToSkip = (outputLineSize - super.msgSize) / 2;
this.msgSize = super.msgSize + charsToSkip;
printLine ();
}
// Define a new method that prints this error message to the output.
// It will be centered (based on the size of outputLineSize).
// linesToSkip lines will be skipped first.
public void printLine () {
WriteLine.printLineWithPosition (getErrorMsg (),
linesToSkip, charsToSkip);
// Print out the two msgSize variables.
System.out.println ("this.msgSize = " +
this.msgSize + ", super.msgSize = " + super.msgSize);
}
}
23. Save and compile this class:
javac PrintfileErrorMsg.java.
24. Now that you've made all of these changes, rerun the HelloWorld applica-
tion. The output should look the same as it did before:
Hello World!
null
Some Text
Some Text
SOME TEXT -> FRENCH TEXT
Some Text for #2
SOME TEXT FOR #2 -> FRENCH TEXT
Some Text for #3
this.msgSize = 48, super.msgSize = 16
MsgSize for PrintfileErrorMsg = 48
Although the output looks unchanged, the program is in fact very different.
You've started to build an infrastructure that will support the ability to print out-
put lines in a standard yet flexible manner. The WriteLineInterface definition, and
the supporting WriteLine class, begin to provide the infrastructure necessary to
manage report creation properly.
Search WWH ::




Custom Search