Beginning of the constructor for the Prob10Runner class

Listing 2 shows the beginning of the constructor

Listing 2. Beginning of the constructor for the Prob10Runner class.
  public Prob10Runner(){//constructor
  
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Compute the minimum dimensions allowed for the
    // display window that will contain the butterfly
    // image rotated at any angle. This turns out to
    // be a square with the length of each side equal
    // to the diagonal length of the butterfly picture.
    //The length of each side was increased by one
    // pixel to guard against loss of precision when
    // converting from double to int.
    int diagonal = 1 + (int)(Math.sqrt(
                        butterflyWidth*butterflyWidth +
                        butterflyHeight*butterflyHeight));

    //Instantiate the picture in which the rotated
    // butterfly image will be displayed.
    display = new Picture(diagonal,diagonal);
    displayWidth = displayHeight = diagonal;

    //This picture provides a white background the same
    // size as the display picture.
    background = new Picture(diagonal,diagonal);

File: as.htm [Next] [Prev]