Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 1. Modify MouseDemo2 class into concentricCircles class. When exe- cuted, your class should open a window (frame) on the screen. Each time when a

image text in transcribed
image text in transcribed
Problem 1. Modify MouseDemo2 class into concentricCircles class. When exe- cuted, your class should open a window (frame) on the screen. Each time when a mouse is clicked anywhere on the screen, your program should draw several con- centric circles around the point where the mouse is clicked. Do not fill the circles. Circles are called concentric if they have the same center, but different radii (ra- diuses). The number of concentric circles drawn each time should be the same as the number of mouse clicks so far. That is, on the first click you draw just one circle, on the second click you draw two concentric circles, on the third click you draw three concentric circles, etc. You can draw the circles using any color you choose, but it should not be black. 8 9 1 import java.awt.*; 2 import javax.swing.JFrame; 3 import java.awt.event.*; 4 class MouseDemo2 extends JFrame implements MouseListener{ 5 public static void main(String[] args) { 6 MouseDemo 2 d new MouseDemo2(); 7 d.setSize(400,400); d.setVisible(true); } 10 MouseDemo2() { 11 addMouseListener(this); 12 } 13 public void mouseClicked(MouseEvent e) { 14 System.out.println("x=" + e.getX() + + "y" + e.getY()); 15 Graphics g = getGraphics(); 16 g.setColor (Color.red); 17 g.filloval(e.getX()-15, e.getY()-15,30,30); 18 > 19 public void mousePressed(MouseEvent e) () 20 public void mouseReleased(MouseEvent e) () 21 public void mouseEntered(MouseEvent e) { } 22 public void mouseExited (MouseEvent e) () 23 24 public void paint (Graphics g) { > 26 27 ) UPOOD NNNNNNN

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

Database Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

More Books

Students also viewed these Databases questions

Question

=+j on to staff their operations in the global marketplace.

Answered: 1 week ago