Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Java program that constructs an Applet. The Applet (JApplet) of your pro

ID: 3827742 • Letter: W

Question

Write a Java program that constructs an Applet.

The Applet (JApplet) of your program should contain three buttons trajectories, "Start", "Clear", and "Color". These three buttons will be organized vertically. Next to each set of buttons, there will be a label "Initial Velocity", then below it, there will be a slider that a user can use to change the initial velocity of trajectories. Below the slider for the initial velocity, there will be another label "Initial Angle", and below it, there will be a slider that a user can use to change the initial angle for trajectories (Note that the angle is measured from 3 oclock location to counter clockwise direction). Next to the buttons and sliders, there are panels, each panel showing trajectories with their initial color. The top trajectories should be red and the bottom one should be blue initially. The picture below shows a snap shot of trajectories. Trajectories consist of multiple filled circles, and its background is black.

When "Clear" button is pushed, trajectories in the corresponding panel should be erased. When "Start" button is pushed, a new trajectory should start drawing using the initial velocity, initial angle, and the color selected at that time from the left hand side of the panel. Pushing the "Color" button opens up a color chooser. Note that a pop-up blocker in your machine might need to be disable for this color chooser to pop up.

By moving each slider, a user should be able to change the initial velocity and initial angle. Note that these two sets of trajectories can have a completely independent movement of each other.

(The size of the applet here is approximately 800 X 340).

You need to create the following classes.

Dot class

The Dot class represents a dot to be drawn on a panel. A collection of dots will draw a trajectory. It has the following attributes:

The following constructor method should be provided:

public Dot(int x1, int y1, Color color1)

The color is initialized to the value of the color parameter. The x and y coordinates are also initialized using their corresponding parameter values.

public void draw(Graphics page)

It should draw a filled dot (circle) using its color, x, y coordinate, and its RADIUS.

TrajectoryPanel class

TrajectoryPanel class a subclass of JPanel class. It is used to define a panel where trajectories are moving. It has the following attributes:

The following constructor method should be provided:

public TrajectoryPanel(Color color)

The color is initialized to the value of the color parameter. The delay should be initialized to 50, and the step should be initialized to delay*50.0, time should be initialize 0.0, initialY should be initialized to 50, angle should be initialized to 45, velocity should be initialized to 50.0. The background should be set to black color.
The timer should be instantiated with "delay" and the listener object created from MoveListener class. Then it should start by calling start() method in the constructor.

The following method should be implemented:

public void resume()

The timer should start again using its start method, and time should be re-initialized to 0.0.

public void clearPanel()

The array list ptList should be cleared and refresh its panel so that trajectories will be erased.

public void changeColor(Color anotherColor)

The changeColor method sets the color of trajectories using the parameter

public void setAngle(int angle1)

It sets the initial angle using the parameter.

public void setVelocity(int velocity1)

This method set the initial velocity using the parameter

public void paintComponent(Graphics page)

It should draw all dots in the array list ptList.

MoveListener class

This class can be defined as a private class of the TrajectoryPanel. It implements ActionListener interface.

public void actionPerformed(ActionEvent event)

Its actionPerformed method defines how a trajectory is drawn by changing its time by adding "step" value to it, and re-compute the new x, y coordinate every time based on the current time, initial velocity, initial angle, initial y coordinate, and gravity.

New x and y should be computed as follows:

int x = (int) (velocity*time*Math.cos((angle/180.0)*Math.PI));
int y = initialY - ((int) (velocity*time*Math.sin((angle/180.0)*Math.PI)-(0.5*GRAVITY*time*time)));

Using x and y values, and the current color, create a new object of Dot class, add it to the array list and re-paint the TrajectoryPanel after such change.
Once y coordinate reaches the top or bottom of its corresponding panel, or x coordinate reaches the left side of its corresponding panel, stop the timer so that it will not keep drawing the trajectory.

TrajectoryControlPanel class

The TrajectoryControlPanel is a subclass of JPanel class. It contains 3 buttons including a start button, a clear button, and a color button. It also contains two labels and two JSlider objects. It also contains one panel -- an object of TrajectoryPanel class. Note that two objects of this class will be used, one for the red trajectories and one for the blue trajectories in the ControlPanel class.

The following constructor method is already given:

public TrajectoryControlPanel(int width, int height, Color initialColor)

Its parameters are width and height of the applet, and the initial color of the trajectories for the panel. It should instantiate each components and arrange them using layout managers. The JSlider for velocity should have its range from 10 to 100, and the initial velocity should be 50. Its major tick spacing should be 10, and it should be shown vertically. The JSlider for the initial angle should have its range from 5 to 85, with the initial value 45. Its major tick spacing should be 10, and it should be shown vertically. You can use other methods defined in JSlider to make your Slider look like the one shown in this page. An object of the ButtonListener class should be added to each button, and an object of the VelocityListener class should be added to the velocity JSlider object, and an object of the AngleListener class should be added to the angle JSlider.

ButtonListener class

This class can be defined as a private class of the TrajectoryControlPanel. It implements ActionListener interface.

public void actionPerformed(ActionEvent event)

Its actionPerformed method should define an action for each button (There are 3 buttons). To distinguish buttons, you can use getSource() method of the ActionEvent object. For instance, if "start" is the start button for the trajectories panel, we can check if that button is pushed as:

public void actionPerformed(ActionEvent event)
{
   if (event.getSource() = = start)
    {
    ...
    }
}

VelocityListener class

This class can be defined as a private class of the TrajectoryControlPanel. It implements ChangeListener interface. You need to provide a definition for the following:

public void stateChanged(ChangeEvent event)

by getting the selected value of the slider, and assign it as a velocity of the corresponding trajectories.

AngleListener class

This class can be defined as a private class of the TrajectoryControlPanel. It implements ChangeListener interface. You need to provide a definition for the following:

public void stateChanged(ChangeEvent event)

by getting the selected value of the slider, and assign it as an angle of trajectories.

Assignment12.java (no need to change)

ControlPanel.java (no need to change)

TrajectoryControlPanel.java (to be completed)

TrajectoryPanel.java (It extends JPanel) (to be completed)

Dot.java (to be completed)

Attribute name Attribute type Description color Color color of the dot. x int x coordinate of the center of the dot y int y coordinate of the center of the dot RADIUS int the radius of the dot. It is 3. JApplet defined in javax.swing ControlPanel width int height int panelNum:int +ControlPanel (int int Assignment 12 Trajectory ControlPanel +init( )void -tPanelTrajectoryPanel color:Color width: int ButtonListener height: int 3 buttons, 2 sliders, 2 labels, 1 color chooser +action Performed Action Event ):void +Trajectory ControlPanel intrint Color Velocity Listener +stateChanged :void AngleListener Move Listener +stateChanged ChangedEvent):void +actionPerformed (ActionEvent :void Arizona State University, CSE205, Assignment 12, Spring 2017 JPanel defined in javax.swing Dot -xint yint color:Color RADIUSint 3 ot int int olor +draw Graphics): void Trajectory Panell color:Color -timer Timer initial Y:int 100 velocity:double 50.0 time:double 0.0 50 delay int step:double delay 0.001 angle:int 45 GRAVITY double 9.8 ptList ArrayList +Trajectory Panel(Color -tresum ee0 void +clearPanel :void +change void +setAngle(int) void +set Velocity (int):void +paintComponent(Graphics): void

Explanation / Answer

TrajectoryControlPanel.java (to be completed)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote