Java代写:COMPSCI230-Bouncing-Program

Introduction - The Bouncing Program

The application, as given, is a simple bouncing program. Different shapes move around in various paths.

Actions

The user can create a new shape by clicking anywhere within the panel area of the program. The properties of the newly created shape are based on the current values saved in the appropriate UI fields (e.g. height, width etc).

Selecting/deselecting shapes:

A user can select a shape by clicking anywhere on the shape. If a shape is selected, all its handles are shown. The user can change the path types/widths/heights for all selected shapes by changing the current values with the help of the tools provided at the top of the application interface. (But the shape type can’t be modified once a shape has been created.)

Clicking on a selected shape will deselect it.

Tools

Shape Combo Box

The ‘Shape’ combo box sets the current shape type for new shapes. Clicking in the panel area for Shape Creation will create the selected type of the shape. A rectangle or a circle can be selected in the program.

Path Combo Box

Users may select one of several moving paths for shapes from the ‘Path’ combo box. Selecting a new path changes the path of all currently selected shapes. Additionally, the new path becomes the current path for any new shapes that are created.

Width TextField

Users may change the current width of new shapes and currently selected shapes by entering a valid number in the width text field and pressing “ENTER”.

Height TextField

Users may change the current height of new shapes and currently selected shapes by entering a valid number in the height text field and pressing “ENTER”.

Border Colour Button

Users may change the current border colour of new shapes and currently selected shapes by selecting a colour from the colour dialog box and pressing “OK”.

Start Button

Starts the animation.

Stop Button

Stops the animation.

Animation Slider

Users may use the animation delay slider to adjust the speed of the animation.

The application has a popup menu, which is activated by clicking the right mouse button anywhere in the panel area (on a windows machine). The popup menu contains a menu item called “Clear All” which allows the user to clear all shapes from the program.

What you are to do

Firstly, become familiar with the program supplied. The files included in the program are as follows:

1
2
3
4
A2.java
AnimationPanel.java
MovingShape.java
MovingRectangle.java

Download all source files from the request course page. The design and implementation of the program will be covered in lectures, please refer to the relevant material. It is strongly recommended to start as early as you can and implement the parts you know as soon as they are taught in lectures.

Your request is divided into several stages for ease of completion. Please complete the request in order of the stages.

Stage 1: Using An ArrayList (10 marks)

In this part you are required to modify classes in A2 which enable users to store instances of shapes using an ArrayList.

Stage 2: Pen Width (5 marks)

In this part you are required to modify classes in A2 which enable users to change the pen width of all the currently selected shapes and the current pen width that will be used when creating new shapes.

You are required to add a setCurrentPenWidth() method into the AnimationPanel class in order to set the pen width of all the currently selected shapes and the pen width that will be used when creating new shapes. You are also required to add a getCurrentPenWidth() method into the AnimationPanel class to return the CURRENT pen width.

You should add the set and get methods to the MovingShape class in order to set or get the pen width of shapes. You should also modify the draw method of MovingRectangle class (and all subclasses) in order to use the pen width attribute stored in the superclass to draw the shape.

Stage 3: Adding new Shapes (25%)

The MovingShape is an abstract class which contains two abstract methods: draw and contains. You are required to add new subclasses. You may need to implement some or all abstract methods for the new shapes. You may also need to add a private instance field to store a specific property of the new shape. You will need to think carefully on the structure of the inheritance hierarchy.

Stage 3B: MovingPolygon Class (10 marks)

You are required to add a new class to the bouncing program. This class should draw a polygon based on the current width, height, pen width, border colour and the bouncing path stored in the AnimationPanel. Some examples are shown in the following diagram. You can choose any one or all of them.

Stage 3C: MovingRotatingSquare Class (10 marks)

You are required to add a new class to the bouncing program. This class should draw a list of rotating squares based on the current width, height, pen width, border colour and the bouncing path stored in the AnimationPanel. Some examples are shown in the following diagram.

You may need to use methods from the AffineTransform class to rotate squares.

Stage 4: Adding a New Path (10 marks): JumpingPath class

In this part, you are required to add a jumping path to the bouncing program.

The MovingPath is an abstract inner class which contains an abstract method. You are required to add a new subclass which extends the MovingPath. You may need to add a private instance field to store a specific property of the new path. You will need to think carefully on the structure of the inheritance hierarchy.

A2 & MovingShape

Next, you are required to add a new ImageIcon to the ‘Path’ combo box control in the A2 class for the new type of path. You are also required to modify the setPath method in the MovingShape class which allows users to create a new subclass instance. An example is shown as below:

Assessment criteria

  • Users should be able to add a new shape which bounce off using the jumping path idea.
  • Users should be able to change the bouncing path of the selected shapes to the jumping path.