Question: Extend your program to work as follows: When the mouse is first pressed, draw a small circle as above. As the mouse is dragged, draw
Extend your program to work as follows: When the mouse is first pressed, draw a small circle as above. As the mouse is dragged, draw a line connecting the original point to the current position of the mouse. Erase the previous line first so that your canvas doesnt get covered in black. When the mouse is released, leave the last line on the canvas. Think about what you need to keep track of between events to make this work. This needs to be part of the state of your canvas. . .
5. Have your canvas implement the java.awt.event.KeyListener interface, add itself as its own KeyListener, and call setFocusable(true) in order to receive keyboard focus. When a key is typed, your program should draw the corresponding character (see KeyEvent.getKeyChar()) on the canvas at the location of the event. If another key is typed without the mouse being clicked, then draw the next character to the right of the previous one as if you were typing in a text field. Again, think about what state you need to maintain to do this. It doesnt have to be perfect (you can hard-code the width of the characters if you like).
6. Let the user change the color used for painting by pressing a number key. Let the different numeric keys correspond to different colors and switch the drawing color depending on which key is pressed. If you want to use the numeric keypad for this, you might look into KeyEvent.getKeyLocation() and KeyEvent.KEY LOCATION NUMPAD, as well as the VK NUMPAD constants
I need to do this in Java. Thank you!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
