Question
Project 1: Paintin' & Animatin' For Proj 1, you'll build on the Dots.java and DotsPanel.java programs (you may revert to the originals, or use your
Project 1: Paintin' & Animatin'
For Proj 1, you'll build on the Dots.java and DotsPanel.java programs (you may revert to the originals, or use your Project 1 as a foundation):
Add the ability to draw continuously while dragging; Add the ability to change the size of new dots by scrolling the mouse wheel up/down; Add animation using a Timer so that the dots all move when drawn.
Add an array for the colors of each dot, make each color random (for fun, use four ints from 0-255 instead of three, to give dots transparency), make each dot move at a different random speed (in x and y directions), and have the dots "bounce" appropriately off all four sides of the screen.
Add the ability to "group" dots whenever the right mouse is dragged (hint: when pressed, remember that dot's speed x/y, then whenever dragging, use that speed x/y for all the 'dragged' dots...).
Add a 10 point slider that will act as a speed multiplier. So when you adjust the slider the current stored speed for the dot will increase by a factor of the current position of the slider.
Have the left click do one thing (e.g. "bubbles") and the right mouse click do another ("group").
Submit just the Java source code files from your project's 'src' folder. The files should contain the following lines of comments (or similar) at the top
// FileName.java // by Name // CSCI 1302 // Project 1 // Date
Additional Deliverable:
Dots.java
DotsPanel.java
Here is a demo of what I am looking for. Your submission does not have to be exactly like this but the functionality should be there:
At the 4 second mark I draw dots while dragging with the left mouse button.
At the 7 second mark I group all the dots with the right mouse button.
At the 20 second I adjust the speed of all the dots with the slider.
import java.awt.BorderLayout; import javax.swing.JFrame; import javax.swing.JSlider; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener;
public class Dots2 { public static void main(String[] args) { JFrame frame=new JFrame("Dots"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JSlider slider; slider=new JSlider(); slider.setMaximum(10); slider.setMinimum(1); slider.setMajorTickSpacing(1); slider.setPaintTicks(true); slider.setValue(1); final DotsPanel dotsPanel=new DotsPanel(); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(dotsPanel,BorderLayout.CENTER); frame.getContentPane().add(slider,BorderLayout.PAGE_END); frame.pack(); frame.setVisible(true); slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent ce) { int value=slider.getValue(); dotsPanel.setSpeedMultiplier(value); } }); } }
import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Point; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; import java.security.SecureRandom; import java.util.ArrayList; import java.util.Random; import javax.swing.JPanel; import javax.swing.Timer;
public class DotsPanel extends JPanel { int speedMultiplier=1; int sizes[]; private int SIZE=6; private ArrayList
I have everything correct but I need to group all of the dots with the right click function. Right now it just groups dots near the mouse and it needs to group all of the dots that are out. The squares also only go to the left and upper edge when the side is adjusted and it needs to go to all edges randomly.
This was the feedback from my professor: Needs to group all the dots. You also need to look at why the squares are going beyond the left and upper edge and not going to the right and bottom edge after I adjust the size of the squares.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started