Problem

The MouseListener interface allows you to retrieve mouse events. A program implements this...

The MouseListener interface allows you to retrieve mouse events. A program implements this interface in a manner similar to the WindowListener interface. For example, the following program creates a J Frame and outputs the X and Y coordinates of any mouse clicks within the J Frame. The MouseListener interface requires the implementing class to define the mouseClicked, mouseEntered, mousePressed, mouseReleased, and mouseExited methods. In the example, only the mouseClicked method has been completed.

import javax.swing.JFrame;import java.awt.event.MouseListener;import java.awt.event.MouseEvent;public class MouseDemo extends JFrame implements MouseListener{public void mouseClicked (MouseEvent e){System.out.println(e.getX() + “ “ + e.getY());}public void mouseEntered (MouseEvent e) {}public void mousePressed (MouseEvent e) {}public void mouseReleased (MouseEvent e) {}public void mouseExited (MouseEvent e) {}public MouseDemo(){super();setSize(600,400);setTitle(“Mouse Demo”);setDefaultCloseOperation(JFrame.EXIT_0N_CL0SE); addMouseListener(this);//Add listener for this object}public static void main(String[] args){MouseDemo m = new MouseDemo(); m.setVisible(true);}}

Modify this program to create a simple drawing program. When the mouse button is clicked, a solid circle with a radius of 3 pixels should be drawn in the JFrame centered at the mouse coordinates. Draw the circle in the color of your choice. Make sure that the drawing is correctly redrawn if the JFrame is minimized and then displayed again.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 18
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT