Lab 11

Purpose

This lab requires you to apply some new concepts in addition to those that you have learned throughout the semester. The new concepts for the lab are inheritance, polymorphism, sorting, and several new GUI components. This lab has several pieces to complete. You are strongly encouraged to take sufficient time to plan and design your program completely BEFORE BEGINNING TO CODE!

Key Reading

  • 2.9 (Graphics class)
  • 5.12 (JRadioButton and JCheckBox)
  • 6.10-6.13 (Layout Managers and Borders)
  • 7.9 (MouseListener)
  • 8.1-8.7 (Inheritance)
  • 9.1-9.4 (Polymorphism)

Introduction

The files needed for this lab assignment are found in the lab 11 zip file. Your assignment essentially is to replicate the program found in the lab11.jar file. You will create an organized java GUI that draws and manipulates various shapes.

Note: Do not decompile the class files of the .jar file or attempt to use the class files to pass off your lab assignment.

Requirements

Part 1 - Neat and Tidy (5 points)

  • Replicate the interface of the lab11.jar file.
  • You may pick any colors you like, but the layout of the buttons and panels and the borders used must match the jar file.
  • The "Manipulate" panel must use a compound border.
  • The size of your GUI does not have to exactly match the jar file. However, you should use the setPreferredSize() method to set your GUI to an appropriate size.

Part 2 - Shapes, Shapes, Shapes (10 points)

  • Add functionality to implement the drawing shapes portion of lab10.jar:
    • As part of the design phase, produce an appropriate UML diagram. You will need to show this diagram to the TA when you pass off. For the classes involved in your inheritance hierarchy, your diagram should include the class name, variables, and methods, with appropriate visibility symbols. For other classes that are not in your inheritance hierarchy, you only need to include the name of the class in the diagram. Appropriate arrows should be used throughout to show relationships between classes. A good example can be found on page 489.
    • Create and display a rectangle, square, circle, or oval when the appropriate button is pressed
      • Draw the center of each shape inside the drawing area
      • The position of each shape is defined by its center point
      • The size of a shape is defined by its dimensions. Think about the similarities in the dimensions of these 4 shapes
      • Each shape has its own randomly generated color
      • Each shape must have a randomly generated center point and demensions. The center point of all newly created shapes must be within your drawing area (the black section of the jar file example).
    • All previously created shapes must be displayed continuously
    • Your shape objects must be stored in a dynamic data structure (no arrays)
    • Organize your shape objects into an appropriate inheritance hierarchy including an abstract parent class
    • The drawing of your shapes must use polymorphism

Part 3 - Draw Options (5 points)

  • If the "fill" checkbox is selected, draw all shapes filled; if not, draw all shapes unfilled
  • If the "coordinates" checkbox is selected, draw the individual center point coordinates at or near the center point of each shape

Part 4 - Manipulation (10 points)

  • If the mouse is pressed inside a shape and the mouse is then dragged:
    • if the "translate" radio button is selected, move the shape that is selected to where the mouse is dragged without changing the size of the shape
    • if the "resize" radio button is selected, resize the shape that is selected as the mouse is dragged across the screen (the center point should not move when the shape is resized)
    • only one shape may be moved or resized at a time
    • If the user clicks on shapes that overlap, the top shape should be selected

Part 5 - Sorted (10 points)

  • Continuously sort the shape objects by y-coordinate (smallest to largest or largest to smallest, whichever you prefer) of the center points; if the y-coordinate of multiple shapes is the same then sort those shapes by x-coordinate (smallest to largest) of the center points. If both the x-coordinates and y-coordinates of multiple shapes are the same, then decide for yourself the order in which you sort those shapes.

Requirement Notes

Design

  • Think carefully about your hierarchical design for your shape objects and your GUI and list interaction. Careful design will save you hours of debugging!
  • You may not use any predefined Java class that implements the Shape interface in your hierarchy.

Images

  • The pictures to use for the shape images for your buttons are contained in the lab 10 zip file.

Oval

  • To determine if a point is inside an oval, use the following equation. If it is true, the oval contains the point: (x/a)^2 + (y/b)^2 <= .25 where x is the distance from the center of the oval in the x direction, y is the distance from the center of the oval in the y direction, a is the "width" of the oval, and b is the "height" of the oval. Please note that ^ does not do exponents in Java. Look in the Math class for a method to do that. See diagram below

Sorting

  • You may use any sorting algorithm you wish.
Designed by Andy Griffin