Question
Write a class called ShapePanel that extends class JPanel. The panel will have six buttons (explanation below): Left, Right, Up, Down, Shape, Color. When the
Write a class called ShapePanel that extends class JPanel. The panel will have six buttons (explanation below): Left, Right, Up, Down, Shape, Color. When the panel load, the center of the panel will be drawn in black filled circle. The following screen image shows the panel after loading:
When clicking on the Left button shape moves 10 pixels to the left. If you cross the border of left side of the window, it will reappear on the right side of the window. When clicking on the Right button, shape moves 10 pixels to the right. If you cross the border of the right side of the window, it will reappear again on the left side of the window. Clicking Up button moves the shape 10 pixels up. If the shape cross the upper limit of the window, it will reappear on the bottom of the window. Clicking Down moves the shape 10 pixels down. If you cross the border of the bottom of the window, it will appear again on the top of the window. Clicking on the Color button change and fill color of the shape of any random color. Clicking the Shape button will change the shape drawn -If the shape is a circle, it will change to a square, or if it is a square, it will change to a circle. For example, the screen image below shows the screen after a few clicks of a button Left, a few clicks of a button Down, clicking Shape and clicking Color:
Comments - To generate a random number, you can use the method Math.random (). This method returns a random number between 0 and 1. You can use this number to get a new color, by the constructor of the class Color that accepts three parameters in the range of 0-255 representing the red, green and blue. - The circle and the square will be both the size of 10x10 pixels
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started