Write a class named Legos1 extending the JFrame class with the followingspecifications.a. Declare the integer type instance variables startX, startY, legoWidth,and legoHeight. The first two values represent the top-left coordinatesof the first red block in the bottom row. The next two values are thewidth and height of each block.b. Declate another integer instance variable, baseLength. This representsthe number of blocks in the bottom row.c. In the constructor, specify the appropriate window title using yourlastName and assign the above instance variables with the values 20,300, 50, 20, and 10, respectively.d. In the paint method, using nested loops, fill the pattern from the bottomrow all the way to the top. Notice, that the number of blocks decreasesby one for each row. Use the baseLength variable to control the loops.e. In the main method, create the application object, set its size to 550 by325 and its visibility to true to test the above graphics.Modify part1 assuming that now you have a bucket of lego blocks with various colors.
Write a newclass Legos2 in the same package for this part.Use an array of Color objects and initializethe array with the colors:Color.red, Color.blue, Color.yellow,Color.green, Color.pink,Color.black, Color.magenta,Color.orange, and Color.cyan.For picking the next color for the block, use a java.util.Radom object and generate a random integer using the nextInt method. Use the length of the colors array as an argument(do not hard code the array length).
Reviews
There are no reviews yet.