Create a Swing GUI application that displays the following graphics of red and blue
cups. The structure is always built from bottom row to top row, left to right in each row.
Write a class named Cups1 extending the JFrame class with the following specifications.
a. Declare the integer type instance variables startX, startY cupWidth,
and cupHeight. The first two values represent the top-left coordinates of
the first cup block in the bottom row. The next two values are the width
and height of each cup.
b. Declate another integer instance variable, baseLength. Thisrepresents
the number of cups in the bottom row.
Declate another integer instance variable, cupSpacing Thisrepresents
the spacing between adjacent cups
In the constructor, specify the appropriate window title using your
lastName and assign the above instance variables with the values 100,
300, 25, 40, 7, and 6, respectively.
e. 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 cups decreases by
one for each row. Use the baseLength variable to control the loops.
In the main method, create the application object, set its size to 550by
550 and its visibility to true to test the above graphics.
Modify part 1 so that the cups look like real cups. Write a newclass Cups2 in the same
package for this part.
For drawing cach cup, use the fillPolygon(int, int, int) method from
java-awt-Graphics- You can reduce the width of the cup on the top by 5 units on the
left and 5 units on the right.
These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction
of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice.
Unethical use is strictly forbidden.
// Import Java Packages
// Suppress serial warnings
// Beginning of Cups1 Class while using a JFrame enclosing the window
public class Cups1 extends JFrame
// Declare the variables
private int startX;
private int startY;
private int cupWidth;
private int cupHeight;
private int baseLength;
private int cupspacing;
// Beginning of Cups1 Constructor
// Window Title Text
// Set the variables
// Ending of Cups1 Constructor
// Beginning of paint method
public void paint(Graphics g)
// Sets the starting x and y coordinates values to current coordinates
int currXCoord = startX;
int currYCoord = startY;
// Used to Paint Frame
// Beginning of Outer For loop to setup the rows portion of the stacked cups
for (int rowVal = 1; rowVal <= baseLength; rowVal++)