Java Reference
In-Depth Information
// 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 ();
System.out.println (tempMsg);
// Print the text item in the original object.
tempMsg = myErrorMsg.getErrorMsg ();
System.out.println (tempMsg);
// Call the new variation of the getErrorMsg method.
// This variation will return an all uppercase message.
tempMsg = myErrorMsg.getErrorMsg ('U');
System.out.println (tempMsg);
}
}
H ELLO W ORLD : T HE A PPLET
import java.applet.Applet;
import java.awt.Graphics;
public class HelloWorld extends Applet {
public void paint(Graphics g) {
String tempMsg;
g.drawString("Hello applet World!", 5, 25);
// Create a new instance of the ErrorMsg class.
ErrorMsg myErrorMsg = new ErrorMsg ();
// Print the contents of the public data member msgText in the class.
tempMsg = myErrorMsg.getErrorMsg ();
g.drawString (tempMsg, 5, 35);
// Set msgText to some text String, and print its contents.
myErrorMsg.setErrorMsg ("Some Text");
tempMsg = myErrorMsg.getErrorMsg ();
g.drawString (tempMsg, 5, 45);
Search WWH ::




Custom Search