Java Reference
In-Depth Information
239
public static void main ( String args [])
240
{
241
// set frame properties
242
Calculator f = new Calculator () ;
243
f.setTitle ( "Calculator Application" ) ;
244
f.setBounds ( 200,200,300,300 ) ;
245
f.setVisible ( true ) ;
246
247
// set image properties and add to frame
248
Image icon = Toolkit .getDefaultToolkit () .getImage ( "calcImage.gif" ) ;
249
f.setIconImage ( icon ) ;
250
251 } // end of main
252 } // end of class
FIGURE 6-36
In line 242, an instance of the Calculator Frame, named f, is constructed.
Recall that the setTitle() method, shown in line 243, takes a String argument,
literal or variable. The argument displays as the title bar caption of the running
application. The setBounds() method in line 244 will cause the Frame to display
300 pixels from the top and 300 pixels from the left of the user's screen, 200
pixels wide and 200 pixels tall. The setVisible() method in line 245 will cause the
Frame to display at the beginning of the application. The setVisible() method is
useful especially when several Frames are used in an application. By using the
setVisible() method, you can decide exactly when or what event will make any
given Frame visible.
In line 248, the image file, calcImage.gif, is extracted from the file system
using the getImage() method of the default toolkit. The setIconImage()
method in line 249 then assigns the image to the Frame's title bar icon. The
following step enters code for the main() method for the Calculator application.
To Code the main() Method
1. Enter lines 239 through 252 as shown in Figure 6-36.
The main() method displays (Figure 6-37).
main() method header
frame constructed
frame attributes set
image added to
frame as icon
closing braces
FIGURE 6-37
 
Search WWH ::




Custom Search