Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

12.17 Interactive Drawing Application In this exercise, you'll implement a GUI application that uses the MyShape hierarchy from GUI and Graphics Case Study Exercise 10.2

image text in transcribedimage text in transcribedimage text in transcribed

12.17 Interactive Drawing Application In this exercise, you'll implement a GUI application that uses the MyShape hierarchy from GUI and Graphics Case Study Exercise 10.2 to create an in teractive drawing application. You'll create two classes for the GUI and provide a test class that aunches the application. The classes of the MyShape hierarchy require no additional changes The first class to create is a subclass of JPanel called DrawPanel, which represents the area on which the user draws the shapes. Class Draw Panel should have the following instance variables a) An array shapes of type yshape that will store all the shapes the user draws b) An integer shapecount that counts the number of shapes in the array c An integer shape Type that determines the type of shape to draw. d) A Myshape currentshape that represents the current shape the user is drawing e) A Color currentColor at represents the current drawing color f) Aboolean filledshape that determines whether to draw a filled shape g) A JLabe 1 status Label that represents the status bar. The status bar will display the co- ordinates of the current mouse position Class DrawPanel should also declare the following methods a) overridden method paintComponent that draws the shapes in the array. Use instance variable shapecount to determine how many shapes to draw. Method paintComponent should also call currentshape's draw method, provided that currentshape is not nu b) Set methods for the shapeType, currentColor and filledShape c) Method clearLastshape should clear the last shape drawn by decrementing instance ariable shapecount. Ensure that shapecount is never less than zero d) Method clearDrawing should remove all the shapes in the current drawing by setting shapecount to zero Methods clearLastShape and clear Drawing should call repaint (inherited from JPanel) to refresh the drawing on the DrawPanel by indicating that the system should call method paintComponent Class DrawPanel should also provide event handling to enable the user to draw with the mouse. Create a single inner class that both extends MouseAdapter and implements M Listener to handle all mouse events in one class In the inner class, override method mousePressed so that it assigns currentshape a new shape e type specified by shapeType and initializes both points to the mouse position. Next, override method mouseReleased to finish drawing the current shape and place it in the array. Set the second point of currentshape to the current mouse position and add currentshape to the array. Instance variable shapecount determines the insertion ind Set currentShape to nu11 and call method repaint to update the drawing with the new shap Override method mouseMoved to set the text of the statusLabel so that it displays the mouse coordinates this will update the label with the coordinates every time the user moves (but does not drag the mouse within the Draw Panel. Next, override method mouseDragged so that it sets the econd point of the currentshape to the current mouse position and calls method repaint. This will allow the user to see the shape while dragging the mouse. Also, update the JLabel in mouse Dragged with the current position of the mouse Create a constructor for DrawPane 1 that has a single JLabel parameter. In the constructor, ini tialize statusLabel with the value passed to the parameter. Also initialize array shapes with 100 entries, shapecount to 0, shapeType to the value that represents a line, currentshape to null and currentColor to Color.BLACK. The constructor should then set the background color of the Draw Panel to Color.WHITE and register the MouseListener and MouseMotionListener so the JPanel properly handles mouse events Next, create a JFrame subclass called DrawFrame that provides a GUI that enables the user to control various aspects of drawing. For the layout of the DrawFrame, we recommend a BorderLay

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

101 Database Exercises Text Workbook

Authors: McGraw-Hill

2nd Edition

0028007484, 978-0028007489

More Books

Students also viewed these Databases questions

Question

=+to live and work wherever he or she wants?

Answered: 1 week ago

Question

=+How will this affect the recruiting process?

Answered: 1 week ago