CSCI 201: Intro to Programming (Java)

Assignment 7.    Due: Fri, Dec 15

Please put your work in directory cs201 on your Linux account before 11:59pm of the day above.

  1. (20 points)   Design a Java Swing application or drawing house similar to the one shown below:

    Set the window size 400x400 pixels.

    Name the project Hw7_1
    Solution

  2. (20 points)   Design a Java Swing application to display your name. Your name has to be centered in the window area, the position must be computed by the application depending on the name and window size. Use "Serif" bold-face font of size 20 pixels. Your name has to appear in a blue box with a 10 pixels padding and be surrounded by the green and red boxes of width 10 pixels each as it is shown below. Set the window size 400 x 200 pixels.

    Name the project Hw7_2
    Solution

  3. (20 points)   Design a Java Swing application for drawing the curve defined by the equations
    x = sin(16*Pi*t) * cos(10*Pi*t)
    y = sin(16*Pi*t) * sin(10*Pi*t)

    as t varies from 0 to 1. The output should be similar to the following:

    Set the window size 300x300 pixels.
    Make sure to scale the curve by multiplying x and y by an appropriate constant so that the curve is stretched out to occupy the entire window area.

    Hint: Divide the interval [0, 1] with 1000 points ti, compute the values of xi and yi at each point ti by using the above formulas, and draw line segments between points (xi-1, yi-1) and (xi, yi) for i=1,2,...,1000.

    Name the project Hw7_3
    Solution

  4. (20 points)   Design a Java Swing application that that would look as close as possible to the one shown below. It should take a value (length) from the text field and convert it into inches or centimeters depending on the button clicked. If "to inches" button is hit, the application must take the number as a length in centimeters and convert it into inches, and vice versa. Set window size 300 x 150 pixels.

    Name the project Hw7_4
    Solution

  5. (20 points)   Design a Java Swing application that that would look similar to the animated image below. Your application should draw animated ball centered in the frame window whose diameter is periodically increasing and decreasing. Set frame refresh period of 10 milliseconds. Set window size 150 x 200 pixels.

    Name the project Hw7_5