Question

his assignment will help the student by: Create shapes using Java code Using and creating colors...

his assignment will help the student by:

  • Create shapes using Java code
  • Using and creating colors with Java
  • Coding JFrames and using the Graphics g method
  • Using Loops (to draw)

Your program will generate a drawing using java. You should draw an object that makes sense, not just spare shapes and colors.

  • You must use at least 3 different shapes
  • You must use at least 2 different fonts
  • You must use at least 2 predefined java colors and one custom-made color
  • You should use one loop to draw something, your choice, for loop or while loop

The program name should be Art .java if you use any other name you will get points deducted.

Students must always follow the JAVA Java coding standards for the class.

Add your name atop of your code as a comment
      //author: your-name here

Submit only the .java file. Do not submit the class file.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

// Art.java

import java.awt.BasicStroke;

import java.awt.Color;

import java.awt.Font;

import java.awt.Graphics;

import java.awt.Graphics2D;

import javax.swing.JFrame;

/**

* This program draw a beautiful flower and some labels using java graphics.

* Oval, Rectangle and Arc shapes are used in this program, along with colors -

* green, black, orange, red and olive (custom)

*

*/

public class Art extends JFrame {

      // constructor initializing GUI

      public Art() {

            setDefaultCloseOperation(EXIT_ON_CLOSE);

            setSize(700, 500);

            setTitle("Art");

      }

      @Override

      public void paint(Graphics g) {

            super.paint(g);

            // getting a Graphics2D object from g

            Graphics2D g2 = (Graphics2D) g;

            // using black color, filling the entire window with black

            g2.setColor(Color.BLACK);

            g2.fillRect(0, 0, getWidth(), getHeight());

            // using white color, drawing a text on the center of screen

            g2.setColor(Color.WHITE);

            // using custom font

            g2.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 40));

            g2.drawString("Enjoy this beautiful flower", getWidth() / 6,

                        getHeight() / 4);

            // using green color, setting a width of 10 pixels

            g2.setColor(Color.GREEN);

            g2.setStroke(new BasicStroke(10));

            // drawing an arc denoting the stem of the flower

            g2.drawArc(getWidth() / 2, getHeight() / 2 - 60, 200, 250, 160, 90);

            // drawing an orange flower at center coordinates with size 70

            drawFlower(g2, getWidth() / 2, getHeight() / 2, 70, Color.ORANGE);

            // drawing a red flower at center coordinates with size 60, so that the

            // previous flower will produce an outline effect

            drawFlower(g2, getWidth() / 2, getHeight() / 2, 60, Color.RED);

            // using a custom color (olive), filling a rectangle at bottom

            g2.setColor(new Color(128, 128, 0));

            g2.fillRect(0, getHeight() - getHeight() / 6, getWidth(), getHeight());

            // using a custom font, drawing a text inside the rectangle

            g2.setFont(new Font(Font.MONOSPACED, Font.BOLD, 30));

            g2.setColor(Color.WHITE);

            g2.drawString("Java Graphics", getWidth() / 2 - 100, getHeight() - 30);

      }

      // method to draw a flower

      // g - graphics/graphics2D object

      // x & y - center coordinates

      // size - size of one petal of the flower

      // c - color of outer petals

      void drawFlower(Graphics g, int x, int y, int size, Color c) {

            // using color c

            g.setColor(c);

            // starting angle

            double angle = -90;

            // angle between each petals (ovals)

            double angle_difference = 360.0 / 5;

            // center x and y coordinates of current petal

            int x1, y1;

            // drawing 5 petals

            for (int i = 0; i < 5; i++) {

                  // finding x, y coordinates of current petal using basic

                  // trigonometry (search for points on a circle)

                  x1 = (int) (x + size / 1.6 * Math.cos(Math.toRadians(angle)));

                  y1 = (int) (y + size / 1.6 * Math.sin(Math.toRadians(angle)));

                  // drawing oval and updating angle

                  g.fillOval(x1 - size / 2, y1 - size / 2, size, size);

                  angle += angle_difference;

            }

            // drawing the middle stigma using yellow color

            g.setColor(Color.YELLOW);

            g.fillOval(x - size / 4, y - size / 4, size / 2, size / 2);

      }

      public static void main(String[] args) {

            // creating and displaying art

            Art art = new Art();

            art.setVisible(true);

      }

}

/*OUTPUT*/

Add a comment
Know the answer?
Add Answer to:
his assignment will help the student by: Create shapes using Java code Using and creating colors...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create the logo as shown in Java in an applet or frame. It should be as...

    Create the logo as shown in Java in an applet or frame. It should be as close as possible, including the Virus Logo. Draw the logo using ovals, lines, rectangles, and strings, changing colors and using draw or fill as necessary. Change to appropriate virus colors (like Blue and Cyan) and fonts for the text in the drawing. Everything should be drawn in paint() with your Graphics object. After creating one virus, usecopyArea() to copy the virus bugs to other...

  • Phython 3 Assignment. Write a graphics program to display (draw) a simple house using at least...

    Phython 3 Assignment. Write a graphics program to display (draw) a simple house using at least 4 shapes and 3 different colors. Add some landscaping too! Please use comments to explain you code

  • Please use JAVA Create an additional drawing panel at least 400 x 400. On it, draw...

    Please use JAVA Create an additional drawing panel at least 400 x 400. On it, draw filled-in shapes of at least two types (rectangles, circles, etc.) in at least two colors. Each shape type should be drawn by its own method (that you write) with parameters indicating where it is to be drawn and how big it is to be. Consider including the color as a parameter as well; this would make the function more flexible. Draw at least ten...

  • Please use JAVA Create an additional drawing panel at least 400 x 400. On it, draw filled-in shap...

    Please use JAVA Create an additional drawing panel at least 400 x 400. On it, draw filled-in shapes of at least two types (rectangles, circles, etc.) in at least two colors. Each shape type should be drawn by its own method (that you write) with parameters indicating where it is to be drawn and how big it is to be. Consider including the color as a parameter as well; this would make the function more flexible. Draw at least ten...

  • This assignment is designed to give you practice with Javadoc, creating unit tests and using Junit....

    This assignment is designed to give you practice with Javadoc, creating unit tests and using Junit. Be sure to follow all style and documentation requirements for THIS class. See the style and documentation requirements posted on Canvas. You are to name your package assign1 and your file Palindrome.java. Palindrome Class Palindrome testString : String + Palindrome (String) + isPalindrome (): boolean The method isPalindrome is to determine if a string is a palindrome. A palindrome, for this assignment, is defined...

  • Use Python's Turtle Graphics module to build an original image build an image using shapes and...

    Use Python's Turtle Graphics module to build an original image build an image using shapes and colors build a repeating or abstract pattern using lines and curves ... or a combination of both! Notes: Be sure to use at least one example if not more of if/elif/else ... for and while< loops Your program must include at least three functions which you have written All of your work should be included within functions and your program should open calling main()...

  • Use Python's Turtle Graphics module to build an original image build an image using shapes and...

    Use Python's Turtle Graphics module to build an original image build an image using shapes and colors build a repeating or abstract pattern using lines and curves ... or a combination of both! Notes: Be sure to use at least one example if not more of if/elif/else ... for and while< loops Your program must include at least three functions which you have written All of your work should be included within functions and your program should open calling main()...

  • For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java...

    For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java program that will input a file of sentences and output a report showing the tokens and shingles (defined below) for each sentence. Templates are provided below for implementing the program as two separate files: a test driver class containing the main() method, and a sentence utilities class that computes the tokens and shingles, and reports their values. The test driver template already implements accepting...

  • Use Python 3 Create a program that uses Turtle to draw shapes. Show the following menu:...

    Use Python 3 Create a program that uses Turtle to draw shapes. Show the following menu: Enter Circle Enter Rectangle Remove Shape Draw Shapes Exit Circles – User inputs position, radius, and color. The position is the CENTER of the circle Rectangles – User inputs position, height, width, color. The position is the lower left-hand corner Colors – Allow red, yellow, blue, and green only Remove – Show the number of items in the list and let the user enter...

  • Create a java project and create Student class. This class should have the following attributes, name...

    Create a java project and create Student class. This class should have the following attributes, name : String age : int id : String gender : String gpa : double and toString() method that returns the Student's detail. Your project should contain a TestStudent class where you get the student's info from user , create student's objects and save them in an arralist. You should save at least 10 student objects in this arraylist using loop statement. Then iterate through...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT