GUI Rectangle Window 1 - Java Sample Program

//Java program to create a window.

import javax.swing.*;
public class RectangleProgramOne extends JFrame
{
private static final int WIDTH = 400;
private static final int HEIGHT = 300;

public RectangleProgramOne()
{
setTitle("Area and Perimeter of a Rectangle");
setSize(WIDTH, HEIGHT);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}

public static void main(String[] args)
{
RectangleProgramOne rectProg = new RectangleProgramOne();
}
}


Notice that the named constants WIDTH and HEIGHT are declared with the modifier
private. This is because we want these named constants to be used only within the class
RectangleProgram. In general, if a named constant, variable, or method is to be used only
within the specified class, then it is declared with the modifier private. Also, note that
private is a reserved word in Java.

No comments: