Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 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.

//******************************************************************** // DotsPanel.java Author: Lewis/Loftus // // Represents the primary panel for the Dots program. //********************************************************************

import java.util.ArrayList; import javax.swing.JPanel; import java.awt.*; import java.awt.event.*;

public class DotsPanel extends JPanel { private final int SIZE = 6; // radius of each dot

private ArrayList pointList;

//----------------------------------------------------------------- // Constructor: Sets up this panel to listen for mouse events. //----------------------------------------------------------------- public DotsPanel() { pointList = new ArrayList();

addMouseListener (new DotsListener());

setBackground(Color.black); setPreferredSize(new Dimension(300, 200)); }

//----------------------------------------------------------------- // Draws all of the dots stored in the list. //----------------------------------------------------------------- public void paintComponent(Graphics page) { super.paintComponent(page);

page.setColor(Color.green);

for (Point spot : pointList) page.fillOval(spot.x-SIZE, spot.y-SIZE, SIZE*2, SIZE*2);

page.drawString("Count: " + pointList.size(), 5, 15); }

//***************************************************************** // Represents the listener for mouse events. //***************************************************************** private class DotsListener implements MouseListener { //-------------------------------------------------------------- // Adds the current point to the list of points and redraws // the panel whenever the mouse button is pressed. //-------------------------------------------------------------- public void mousePressed(MouseEvent event) { pointList.add(event.getPoint()); repaint(); }

//-------------------------------------------------------------- // Provide empty definitions for unused event methods. //-------------------------------------------------------------- public void mouseClicked(MouseEvent event) {} public void mouseReleased(MouseEvent event) {} public void mouseEntered(MouseEvent event) {} public void mouseExited(MouseEvent event) {} } }

//******************************************************************** // Dots.java Author: Lewis/Loftus // // Demonstrates mouse events. //********************************************************************

import javax.swing.JFrame;

public class Dots { //----------------------------------------------------------------- // Creates and displays the application frame. //----------------------------------------------------------------- public static void main(String[] args) { JFrame frame = new JFrame("Dots"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().add(new DotsPanel());

frame.pack(); frame.setVisible(true); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

50 Tips And Tricks For MongoDB Developers Get The Most Out Of Your Database

Authors: Kristina Chodorow

1st Edition

1449304613, 978-1449304614

More Books

Students also viewed these Databases questions

Question

WHAT IS AUTOMATION TESTING?

Answered: 1 week ago

Question

What is Selenium? What are the advantages of Selenium?

Answered: 1 week ago

Question

Explain the various collection policies in receivables management.

Answered: 1 week ago