Spreadsheet applet:
The spreadsheet applet uses several interesting methods to place objects precisely on the frame. As displays in
Listing 20.8, centering the title horizontally in a in the title area included five steps.
1. Acquiring the dimension of the frame
2. Determining the pixel of the title from the width of the frame
3. Subtracting the length of the title form difference in font size
4. Adding in a factor in which accounts for differences in font size.
5. Dividing the result 2
The value you acquire through doing this is the x coordinates for the starting o the title. You also require a y coordinate for the title. Since the height of the title area is associative to the font size used and the font size is used to help determine this coordinate.
Further, the paint ( ) method draws the input area through simply filling a rectangle along with a color based on the value of the inputColor object. A beginning location for the upper left corner of the input area is determined through moving vertically down the height of one cell. A width of the input area is set to the width of the frame and the height is set to the height of one cell. At last the paint ( ) method draws the individual cells,. For crater them, use a series of draws, the search adds the horizontal lines for rows by using the draw3DRect method of the Graphics class. Blue numerals representing the row numbers are added as Appropriate as the 3D lines are drawn to the frame. A second draw adds the vertical lines for columns, again by using the draw3DRect method. Like the 3D lines are drawn to the frame, red letters representing the column letter are added as appropriate. At last data is added to the cells through a painting the values related along with a cell precisely inside the rectangles created through the previous draws The last section of code in the paint ( ) method, while only a few lines, is important to the spread sheet., a line of code using the draw3DRect( ) method draws a 3D line above the input area and on the left side of the frame. The further to last line calls the paint ( ) methods of the inputArea class, that ensures that the data related along with the currently chosen cell is painted to the input area.