Java is the future !: Chapter 2: Positioning text version pt.1

Saturday, August 14, 2010

Chapter 2: Positioning text version pt.1

Just as we did with the previous program it displays as label. It is identical to the previous one with a single exception that the TextOne object is displayed instead of the Label object.

What is a TextOne object?

It's not part of the standard library like the label was. This is a class of our own. A Canvas object is a displayable component just like a label except the Canvas object doesn't do anything but provide a blank window and permission to draw graphics of our own. So the TextOne class extends the Canvas class and adds a method to draw a single line of text.

The paint method is called by java whenever TextOne object needs to be displayed. Whenever the TextOne window first appears the paint method is called to draw the content of the window. (Paint method is called again if any changes happens like size change etc to redraw the window)

Graphics object is passed to paint method.

Setsize method specifies the original size of the window.




No comments:

Post a Comment