Transcribed TextTranscribed Text

Part 1 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. - Kalathur's Cups_v1 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. c. Declate another integer instance variable, cupSpacing Thisrepresents the spacing between adjacent cups d. 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. f. In the main method, create the application object, set its size to 550by 550 and its visibility to true to test the above graphics. Part 2 Modify part 1 so that the cups look like real cups. Write a newclass Cups2 in the same package for this part. Kalathur's Cups2 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.

Solution PreviewSolution Preview

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.

package cs520.hw4;
// Import Java Packages
import javax.swing.JFrame;
import java.awt.Graphics;
import java.awt.Color;
// 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
public Cups1()
// Window Title Text
super("Ali's Cups1");
// 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++)

By purchasing this solution you'll be able to access the following files:

for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats