Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In java run through eclipse Stage 2: (6 points) Allow users to draw! NOTE: If you can get AT LEAST get the clicking to work

In java run through eclipse

Stage 2: (6 points) Allow users to draw! NOTE: If you can get AT LEAST get the clicking to work (but dragging does not), you can still receive MOST of the points for this stage and you can thus continue on with the rest of the exam. When a user presses the mouse down, a dot of the current radius and color should appear on the screen and stay there. If the user drags the mouse (with button down) one dot after another should be painted on the screen creating a line of dots. The size of the dot painted in Stage 2 should be based on the dots current size which can be changed by the user clicking the Increase Brush Size or Decrease Brush Size buttons implemented in Stage 1. In Stage 4 (below) you will implement a button that allows the user to change the dots color. This ought to feel familiar to the experience of using a drawing program you might have used before. For this stage, you must write a class that implements 2 different interfaces (or two classes that each implement one of the interfaces), which are the MouseListener and MouseMotionListener interfaces. One handles if the mouse was pressed and the other handles when the mouse is pressed and dragged. Putting them together gives the total functionality for this step. If you write a class named BrushListener, then the declaration should look like: public class PaintBrushListener implements MouseListener, MouseMotionListener { //your code here } The MouseListener interface has 5 methods whereas the MouseMotionListener has 2 methods. The MouseMotionListener is the one that handles when the mouse is pressed and dragged. Of these methods, you only need to handle the case if the mouse is pressed, or if the mouse is dragged. When you create an instance of this class, as in: PaintBrushListener clickListener = new ; You will need to add this instance to the component declared in the PaintBrushViewer class named c. The component must add the variable clickListener as BOTH a MouseListener and a MouseMotionListener. You will thus call two different add methods on c, one to add clickListener as a MouseListener and a second to add clickListener as a MouseMotionListener. You should find these two separate methods in the API for a JComponent.

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_2

Step: 3

blur-text-image_3

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

A Complete Guide To Data Science Essentials

Authors: Miguel

1st Edition

9358684992, 978-9358684995

More Books

Students also viewed these Databases questions

Question

Why, ultimately, does possessing a good knowledge of style matter?

Answered: 1 week ago

Question

None.

Answered: 1 week ago