Java Reference
In-Depth Information
// Call the setErrorMsg method to set the text to some other text, and
// print its contents.
myErrorMsg.setErrorMsg ("Some New Text");
tempMsg = myErrorMsg.getErrorMsg ();
g.drawString (tempMsg, 5, 55);
// Create a new instance of the ErrorMsg class.
ErrorMsg myErrorMsg2 = new ErrorMsg ();
// Set the text item to some text String, and print its contents.
myErrorMsg2.setErrorMsg ("Some Text for #2");
tempMsg = myErrorMsg2.getErrorMsg ();
g.drawString (tempMsg, 5, 75);
// Print the text item in the original object.
tempMsg = myErrorMsg.getErrorMsg ();
g.drawString (tempMsg, 5, 85);
// Call the new variation of the getErrorMsg method.
// This variation will return an uppercase message.
tempMsg = myErrorMsg.getErrorMsg ('U');
g.drawString (tempMsg, 5, 95);
}
}
E RROR M SG : T HE C LASS
public class ErrorMsg {
// Define some public class instance variables.
public String msgText = " ";
public int msgSize;
// Define a public method.
public void setErrorMsg (String inputMsg) {
// Modify one of the public variables. Set this variable to the text
// String that was passed as a parameter.
msgText = inputMsg;
// Return from this method. Since this method has no return value
// (i.e., it is declared as void), no return statement is necessary.
}
Search WWH ::




Custom Search