Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help in order to draw a sailboat in the water. Need to add three extra polygons in the paint method. The programming language has

Need help in order to draw a sailboat in the water. Need to add three extra polygons in the paint method. The programming language has to be Java.

package January;

import java.awt.*;

import javax.swing.*;

// Class BeachCanvas definition derived from Canvas class

class BeachCanvas extends Canvas

{

// Default constructor

public BeachCanvas()

{

// Set the Canvas size

setSize(630, 630);

}// End of default constructor

// Defines paint method. Takes Graphics class object as parameter

public void paint(Graphics g)

{

// Sets the graphics color to RGB pattern color

g.setColor(new Color(234, 206, 106));

// DRAWS BROWN RECTANGLE AT THE BOTTOM

// Draws the polygon by calling the graphics class method drawPolygon

// Syntax: void drawPolygon(int xCoordinates[], int yCoordinates[], int numOfPoints)

g.drawPolygon(new int[]{0,0,630,630}, new int[]{450,630,630,450}, 4);

// Fills the polygon by calling the graphics class method fillPolygon

g.fillPolygon(new int[]{0,0,630,630},new int[]{450,630,630,450},4);

// DRAWS SEA GREEN RECTANGLE AT THE TOP OF BROWN RECTANGLE

g.setColor(new Color(32, 178, 170));

g.drawPolygon(new int[]{0,0,630,630}, new int[]{300,450,450,300}, 4);

g.fillPolygon(new int[]{0,0,630,630}, new int[]{300,450,450,300},4);

// DRAWS SKY BLUE RECTANGLE AT THE TOP OF SEA GREEN RECTANGLE

g.setColor(new Color(0, 191, 255));

g.drawPolygon(new int[]{0,0,630,630}, new int[]{0,300,300,0}, 4);

g.fillPolygon(new int[]{0,0,630,630}, new int[]{0,300,300,0},4);

// DRAWS THE YELLOW CIRCLE FOR SUN

g.setColor(new Color(255, 255, 0));

// Draws the oval by calling the graphics class method drawOval

// Syntax: void drawOval(int top, int left, int width, int height)

// Same width and height will draw circle

g.drawOval(100, 100, 80, 80);

g.fillOval(100, 100, 80, 80);

// DRAWS THE RED ARC FOR UMBRELLA

g.setColor(new Color(255, 0, 0));

// Draws the oval by calling the graphics class method drawOval

// Syntax: void drawArc(int top, int left, int width, int height, int startAngle, int sweepAngle)

g.drawArc(400, 400, 200, 125, 330, 190);

g.fillArc(400, 400, 200, 125, 330, 190);

// DRAWS THE VERY LIGHT GRAY TRIANGLE INSIDE UMBRELLA

g.setColor(new Color(252, 252, 252));

g.drawPolygon(new int[]{540,449,560}, new int[]{405,452,485}, 3);

g.fillPolygon(new int[]{540,449,560}, new int[]{405,452,485}, 3);

// DRAWS THE DARK BROWN RECTANGLE FOR STICK OF THE UMBRELLA

g.setColor(new Color(140, 45, 13));

g.drawPolygon(new int[]{497,450,460,510}, new int[]{466,570,580,470}, 4);

g.fillPolygon(new int[]{497,450,460,510}, new int[]{466,570,580,470}, 4);

}// End of paint method

}// End of class

// Driver class AtTheBeach definition

public class AtTheBeach

{

// main method definition

public static void main(String args[])

{

// Creates BeachCanvas class object

BeachCanvas beachCanvas = new BeachCanvas();

// Creates a frame and sets the title

JFrame frame = new JFrame("Monring at each");

// Sets the frame bounds

frame.setBounds(30, 30, 630, 630);

// Attaches BeachCanvas class object to show the drawing

frame.add(beachCanvas);

// Sets the visible property of the frame to true for visible

frame.setVisible(true);

}// End of main method

}// End of driver class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions