Java Reference
In-Depth Information
public RectangleProgram()
{
setTitle("Area and Perimeter of a Rectangle");
setSize(400, 300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible( true );
}
You could create a window by using an object of type JFrame . However, for our
program, if we do so, then the window created will not have a title or the required size
unless we specify the necessary statements similar to the ones in the preceding code.
Because RectangleProgram is also a class , we can create objects of type
RectangleProgram . Because the class RectangleProgram extends the definition
of the class JFrame , it inherits the properties of the class JFrame .Ifwecreateanobjectof
type RectangleProgram , not only do we create a window, but the created window will also
have a title and a specific size, and the window will be displayed when the program executes.
Consider the following statement:
RectangleProgram rectObject = new RectangleProgram();
//Line 5
This statement creates the object rectObject of type RectangleProgram .
The statement in Line 5 causes the window shown in Figure 6-4 to appear on the screen.
FIGURE 6-4 Window with the title Area and Perimeter of a Rectangle
You can close the window in Figure 6-4 by clicking the ''close'' button, the button
containing the , in the upper-right corner. The window in Figure 6-4 is empty because
we have not yet created labels, text fields, and so on.
 
Search WWH ::




Custom Search