|
Why not use System.out.println("Some Message") to put some text on the monitor? A good answer might be:It is legal to do this --- but the text will appear in the DOS window where println has always put it, not in the Frame where you want it. | ||
The drawString() methodOrdinarily a child class inherits every method defined in its parent class. A child overrides a method in its parent by defining a new method with the same signature. Now the new method will be used in place of the parent's method in a child object. When the Java system needs to paint a myFrame object it will automatically do most of the work and then call paint() in the myFrame object to do whatever extra the programmer wants. The work that is automatically done is a great deal of work---involving all the graphics of Java and the operating system and control of the graphics board. At the tail end of all that you get to ask for the little extra bit that you are interested in. Our paint() looks like this:
The parameter g is a reference to a Graphics object. The Graphics object represents the part of the Frame that you can draw on. One of its methods is drawString( String st, int X, int Y ) which will draw a String on the graphics area at location starting X pixels from the left and Y pixels from the top. Here is the MyFrame again, with a few changes.
| ||
QUESTION 13:Fill in the blanks so that when a myFrame object is drawn it will contain "Hello" written at the extreme left about halfway down (assume that the frame is width=150, height=100.) Click Here after you have answered the question |