Java Reference
In-Depth Information
public void printLine () {
int i;
// Print out some blank lines.
for (i=0; i != linesToSkip; i++)
System.out.println ();
// Print out some blank characters so that the error message text is
// centered.
for (i=0; i != charsToSkip; i++)
System.out.print (' ');
// Print out the error message.
System.out.println (getErrorMsg ());
}
}
12. Save and then compile this class in the DOS command window:
javac PrintfileErrorMsg.java
13. Edit the HelloWorld application so that it uses this new class. Using the text
editor, open the HelloWorld.java source file and add these bolded lines of
code to the bottom of the class:
// Create a new instance of the PrintfileErrorMsg class.
PrintfileErrorMsg myErrorMsg3 = new PrintfileErrorMsg ();
myErrorMsg3.linesToSkip = 2;
// Set the text item to some text String, and print its contents.
myErrorMsg3.setErrorMsg ("Some Text for #3");
// Print this data member in PrintfileErrorMsg.
System.out.println ("msgSize for PrintfileErrorMsg = " +
myErrorMsg3.msgSize);
14. Save, compile, and rerun the HelloWorld application. The output should
look like this:
Hello World!
Some Text
Some Text
SOME TEXT -> FRENCH TEXT
Some Text for #2
SOME TEXT FOR #2 -> FRENCH TEXT
Search WWH ::




Custom Search