Please written by computer source In this lab you will create and fill a two-dimensional array of 25 Rectangle objects, arranged in a 5x5 grid. Each Rectangle should have dimensions 100x100, and be arranged on your window so that there is no space between Rectangles. Each Rectangle object should start with one fill color (e.g. white) and when pressed with the mouse it should toggle to a second color (e.g. gray). Pressing a second time on the Rectangle should toggle it’s fill color back to the first color. 3. Use the following template for your main() method. Add missing statements necessary to create your two- dimensional 5x5 Rectangle array and nested for-loops to fill the array with 25 new Rectangle objects, located on your window in a regular 5x5 grid. Make sure to set the mouse-pressed event handler for each new Rectangle. 2. Declare at least two public static variables: a 2D array of Rectangle objects, and a Pad variable: public static Pad pad; public static void main(String[] args) { // Set the title and dimensions of your window. pad = new Pad("Lights Out", 500, 500); // Create the new Rectangle array to hold 25 Rectangle objects in a 5x5 array. // ... // Used nested for-loops to fill the array with Rectangle objects // and set mouse-pressed handler method for each new Rectangle. // ... } 4. Use the following method template to handle mouse-pressed events for all Rectangles. Toggle the fill color of the pressed Rectangle by inspecting the current fill color and using an if-statement to set a new fill color. // When a light is pressed, toggle the light public static void onMousePressed(Shape shp, double x, double y, int button) { // Compute Rectangle array indexes from mouse coordinates. int r = (int)Math.floor(y/100.0); int c = (int)Math.floor(x/100.0); // Use the computed array indexes to get a reference to the pressed Rectangle. // Check if the Rectangle (light) is on by inspecting its fill color elements. // Toggle fill color using an if-statement. // ... }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please written by computer source

In this lab you will create and fill a two-dimensional array of 25 Rectangle objects, arranged in a 5x5 grid.

Each Rectangle should have dimensions 100x100, and be arranged on your window so that there is no space between Rectangles.

Each Rectangle object should start with one fill color (e.g. white) and when pressed with the mouse it should toggle to a second color (e.g. gray).

Pressing a second time on the Rectangle should toggle it’s fill color back to the first color.

3. Use the following template for your main() method. Add missing statements necessary to create your two- dimensional 5x5 Rectangle array and nested for-loops to fill the array with 25 new Rectangle objects, located on your window in a regular 5x5 grid. Make sure to set the mouse-pressed event handler for each new Rectangle.

2. Declare at least two public static variables: a 2D array of Rectangle objects, and a Pad variable: public static Pad pad; public static void main(String[] args) { // Set the title and dimensions of your window. pad = new Pad("Lights Out", 500, 500); // Create the new Rectangle array to hold 25 Rectangle objects in a 5x5 array. // ... // Used nested for-loops to fill the array with Rectangle objects // and set mouse-pressed handler method for each new Rectangle. // ... }

4. Use the following method template to handle mouse-pressed events for all Rectangles. Toggle the fill color of the pressed Rectangle by inspecting the current fill color and using an if-statement to set a new fill color. // When a light is pressed, toggle the light public static void onMousePressed(Shape shp, double x, double y, int button) { // Compute Rectangle array indexes from mouse coordinates. int r = (int)Math.floor(y/100.0); int c = (int)Math.floor(x/100.0); // Use the computed array indexes to get a reference to the pressed Rectangle. // Check if the Rectangle (light) is on by inspecting its fill color elements. // Toggle fill color using an if-statement. // ... }

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Passing Array as Argument
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education