View the step-by-step solution to:

Part 1 (50 points) Create a Swing GUI application that displays the following graphics of red and blue lego blocks. The tower is always built from...

I really need help on my JAVA assignment. Thanks ahead!



Part 1 (50 points) Create a Swing GUI application that displays the following graphics of red and blue
lego blocks. The tower is always built from bottom row to top row, left to right in each
row. Donald's. LEGO: Write a class named Legosf extending the JFrame class with the following
specifications. a. Declare the integer type instance variables stan‘X, startY, legoWidth,
and IegoHeight. The first two values represent the top-left coordinates
of the first red block in the bottom row. The next two values are the
width and height of each block. b. Declare another integer instance variable, baseLength. This represents
the number of blocks in the bottom row. 0. In the constructor, specify the appropriate window title using your
IastName 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 bottom
row all the way to the top. Notice that the number of blocks decreases
by 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 by
325 and its visibility to true to test the above graphics. Note: For each block, use the fl 7 '; method of the Graphics object
Use a value of 2 for arcWidth and arcHeight
htt : 'avase 6 docs a i 'ava awt Gra hics.html


Part 2 (50 points) Modify part1 assuming that now you have a bucket of [ego blocks with various colors.
Write a newciass LegosZ in the same package for this part. Use an array of Color objects and initialize the array with the colors:
Color . red, Color . blue, Color . yellow,,,, Color.magenta,
Color. orange, and Color. cyan. For picking the next color for the block, use a java.util.Random 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]. Since the colors are picked at random, the output varies for each invocation. A
sample output is shown below. Donald's LEGOs


BONUS (10 points) Modify part2 and write the Leg053 version so that the same color is not picked
consecutively. A sample output is shown below. Donald'sLEGOs _ D X Submission Create an archive of your Eclipse project using the following steps. Select the
HW4_lastName project in the Eclipse IDE's Package Explorer or the Navigator window. Click File->Export. Select the General->Archive File option. Click Next.
Specify the “ To archive file:” entry as say, C:\Temp\
The zip file will be created and stored in the C:\Temp folder. Submit this zip file as an attachment in the Assignment Section.

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.


Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question