Assignment12-CSE205

Minimal Submitted Files

You are required, but not limited, to turn in the following source files:

Assignment12.java (The Assignment12 class extends JApplet — no need to change) 
ControlPanel.java (It extends JPanel — no need to change) 
BeamsControlPanel.java (It extends JPanel, to be completed) 
BeamsPanel.java (It extends JPanel) 
You may add more classes or more methods than the specified ones. (You might need them.)Skills to be Applied:

Swing/AWT,
Animation/Multi-Threads
Classes may be needed:  
Timer in javax.swing package, JApplet, JButton, Container, JPanel, Color, Graphics, JSlider, JLabel, JColorChooser, ActionListener, ActionEvent, ChangeListener, ChangeEvent. You may use other classes. Program Description

Suggested Class Diagram:

Write a Java program that constructs an Applet.

The Applet (JApplet) of your program should contain three buttons for beams, “Start”, “Stop”, and “Color”. These three buttons will be organized vertically. Next to each set of buttons, there will be a label “Delay”, then below it, there will be a slider that a user can use to change the delay (speed) of beams. Note than if the delay (interval) of beams decreases, its speed will be faster. Next to the slider for delay, there will be another label “Beam Num”, and below it, there will be a slider that a user can use to change the number of beams for beams. Below the buttons and sliders, there are panels, each panel showing beams with their initial color. The left beams should be red and the right one should be blue initially. The picture below shows a snap shot of beams. Beams consist of multiple filled arcs determined by the number of beams, and its background is black.

When “Stop” button is pushed, corresponding beams stop. When “Start” button is pushed, the beams start moving, i.e., their beams will start extending from its center towards outside. 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 delay interval of beams or their number of beams. When a delay decreases, the corresponding beams should move faster, and when a delay increases, the beams should move slower. Note that these two sets of beams can have a completely independent movement of each other.

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

You can click on this site to see how the applet should work

You need to create the following classes.BeamsPanel class

BeamsPanel class a subclass  of JPanel class. It is used to define a panel where beams are moving. It has the following additional attributes:Attribute nameAttribute typeDescriptioncolorColorcolor of the beams.timerTimerAn object of Timer in javax.swing package. This is used to control the beams’ movement.delayintdelay of the timer.stepinteach step that the beams move, i.e. how much diameter increases for each timer tickcenterXintx coordinate of the center of the beams.centerYinty coordinate of the center of the beams.diameterintthe diameter of the beams.diameterLimitintThe longest the diameter of the beams can become.beamNumintThe number of beams.angleSizeintthe angle size of each beam, determined by the number of beams.

The following constructor method should be provided:

public BeamsPanel(Color color, int width)

The color is initialized to the value of the color parameter. The delay should be initialized to 20, and the step should be initialized to 3. The background should be set to black color. The centerX and centerY should be initialized to (width/2). The diameterLimit should be initialized to (width-10)/2, and the diameter should be initialized to 0 since the beams will spread from inside to outside. The beamNum should be initialized to 8. The angleSize should be initialized to 360/(beamNum*2).  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.

public void suspend()

The timer should stop using its stop method.

public void changeColor(Color anotherColor)

The changeColor method sets the color of beams using the parameter

public void setBeamNumber(int beam)

It sets the number of beams using the parameter.

public void setDelay(int delayValue)

This method set the delay of the timer using its parameter. (Hint: setDelay method of the Timer class)

public void paintComponent(Graphics page)

A color of the beams (arcs) should be set, and beams should be drawing using the coordinate (centerX, centerY) and diameter. Since the beamNum might have been changed, the angleSize should be re-set to 360/(beamNum*2)  (– example, to have 8 beams, each angle size will be 360 degree/(8*2) since there will be a space between beams.)

The fillArc method should be used, but the first two parameters are the upper left corner of the bounding rectangle, so its radius (half of diameter) should be subtracted as:

page.fillArc(centerX-diameter/2, centerY-diameter/2, diameter, diameter, currentAngle, angleSize);

where “currentAngle” starts with 0 and goes up to 360 degrees, and increased by 2*angleSize in each step. Thus this line should be repeated in a loop to draw all beams.

MoveListener class

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

public void actionPerformed(ActionEvent event)

Its actionPerformed method defines how the beams (arcs) should move next, by changing its diameter by adding “step” value to it, and re-paint the BeamsPanel after such change. Note that once the diameter reaches the diameterLimit value, then it should be re-set to 0 so that the beams start again from its center to outside.

 BeamsControlPanel class

 

The BeamsControlPanel is a subclass of JPanel class. It contains 3 buttons including a start button, a stop button, and a color button. It also contains two labels and two JSlider objects. It also contains one panel — an object of BeamsPanel class. Note that two objects of this class will be used, one for the red beams and one for the blue beams in the ControlPanel class.

 

The following constructor method is already given:

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

Its parameters are width and height of the applet, and the initial color of the beams for the panel. It should instantiate each components and arrange them using layout managers. The JSlider for delay should have its range from 0 to 50, and the initial delay should be 20. Its major tick spacing should be 10, and it should be shown vertically. The JSlider for beam number should have its range from 4 to 36, with the initial value 8. Its major tick spacing should be 4, 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 SpeedListener class should be added to the delay JSlider object, and an object of the BeamListener class should be added to the beam number JSlider.

ButtonListener class

This class can be defined as a private class of the BeamsControlPanel. 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 beams panel, we can check if that button is pushed as: 

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

SpeedListener class

This class can be defined as a private class of the BeamsControlPanel. 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 delay of the corresponding beams.

BeamListener class

This class can be defined as a private class of the BeamsControlPanel. 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 number of beams.

 

WHY SHOULD YOU HIRE EXPERT ACADEMIC WRITERS?

Answering this question is not essay as it seems. It will require you to research or burn your brain power, write your findings down, edit, proofread severally, and submit unsure of the grade you will get. Classaider.com assignment writers are offering to take care of that. Order your assignment now, relax, submit, and enjoy excellent grades. We guarantee you 100% original answers, timely delivery, and some free products.

>>ORDER NOW<<

>>SEE TOP WRITERS<<