Question

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 shapes in an attractive pattern; do something fun and interesting of your own design.

(1)Use a Random object or random() method for creating different colors.

What You Should Use?

Constants and variables

Definite loops

Drawing panel and graphics objects

A single main program that draws both drawings

What You Shouldn’t Use?

Selection control structures, unless you are doing something way “above and beyond” the specification.

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

solution

// Drawing.java import java.awt.Graphics; import java.awt.Color; public class Drawing public static final int WIDTH 2 VALUE40draw Pyramid (penvalue) draw_UFO (penvalue); draw_Alien (penvalue); draw_Arc (penvalue); // draw pyramid public static void d//draw UFO public static void draw_UFO (Graphics penvalue) penvalue.setcolor (new Color (150, 150, 150)) int x WIDTH 2 VALUEpenvalue.fillRect (x, y,70,40) penvalue.setColor (Color.black); penvalue.drawRect (x, y, 70,40); public static void draw_Alie//dnose penvalue.drawArc (x + 35, y + 40, 10,20, 0, 25); penvalue.drawArc (x 30, y + 35, 10.20, 0. 25) penvalue.drawstring(W

//output

Djavac Drawing.java DNjava Drawing

Drawing Panel WE ARE ALIENS

//copyable code

// Drawing.java

import java.awt.Graphics;

import java.awt.Color;

public class Drawing

{

     public static final int WIDTH_2_VALUE = 400;

     public static final int HEIGHT_2_VALUE = 400;

     public static final int WIDTH = 500;

     public static final int HEIGHT = 500;

     public static final int COUNT = 5;

     public static final int left=1;

     public static final int top=1;

    public static void main(String[] args) {

        

         drawFigure1();

     }

       public static void drawFigure1() {

         DrawingPanel canvas2 = new DrawingPanel(WIDTH_2_VALUE, HEIGHT_2_VALUE);

         canvas2.setBackground(new Color(0, 200, 255));

         Graphics penvalue = canvas2.getGraphics();

        penvalue.setColor(get_RandomColor());

        penvalue.fillRect(0, HEIGHT_2_VALUE / 2, WIDTH_2_VALUE, HEIGHT_2_VALUE);

        draw_rectangle(penvalue);

        draw_Pyramid(penvalue);

     draw_UFO(penvalue);

        draw_Alien(penvalue);

        draw_Arc(penvalue);

       

       

     }

    // draw pyramid

    public static void draw_Pyramid(Graphics penvalue) {

         penvalue.setColor(new Color(255, 208, 0));

         int x = WIDTH_2_VALUE/5;

         int y = HEIGHT_2_VALUE/5;

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

             penvalue.fillRect(x - (i*3), y + (i*3), 5 + (i*6), 3);

         }

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

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

             penvalue.drawRect(x - (i*3), y + (i*3), 5 + (i*6), 3);

         }

     }

    //draw UFO

    public static void draw_UFO(Graphics penvalue) {

         penvalue.setColor(new Color(150, 150, 150));

        int x = WIDTH_2_VALUE* 3/4;

        int y = HEIGHT_2_VALUE/7;

         penvalue.fillOval(x, y, 70, 16);

         penvalue.drawLine(x + 15, y + 20, x + 30, y + 15);

         penvalue.drawLine(x + 40, y + 15, x + 55, y + 20);

     }

   public static void draw_Arc(Graphics penvalue) {

         penvalue.setColor(new Color(110, 255, 150));

        int x = WIDTH_2_VALUE/2;

        int y = HEIGHT_2_VALUE/2;

        penvalue.drawArc(60, 70, 100, 100, 0, 130);

        penvalue.fillArc(200, 70, 100, 100, 0, 130);

        

     }

public static void draw_rectangle(Graphics penvalue) {

         penvalue.setColor(new Color(150, 150, 150));

         int x = WIDTH_2_VALUE/2;

         int y = HEIGHT_2_VALUE/2;

       

            penvalue.fillRect(x,y,70,40);

            penvalue.setColor(Color.black);

            penvalue.drawRect(x,y,70,40);

    }

    public static void draw_Alien(Graphics penvalue) {

         penvalue.setColor(new Color(110, 255, 60));

        int x = WIDTH_2_VALUE/2;

         int y = HEIGHT_2_VALUE/2;

        //draw head

         penvalue.fillOval(x, y, 80, 60);

         penvalue.fillOval(x+10, y, 60, 80);

         penvalue.fillOval(x + 32, y + 80, 15, 60);

        //arms

         penvalue.drawLine(x + 37, y + 80, x + 20, y + 140);

         penvalue.drawLine(x + 42, y + 80, x + 59, y + 140);

        penvalue.setColor(Color.BLACK);

        //eyes

         penvalue.fillOval(x + 5, y + 10, 10, 20);

         penvalue.fillOval(x + 35, y + 10, 10, 20);

        //dnose

         penvalue.drawArc(x + 35, y + 40, 10,20, 0, 25);

         penvalue.drawArc(x + 30, y + 35, 10,20, 0, -25);

        penvalue.drawString("WE ARE ALIENS", x - 5, y - 10);

     }

     // This function random values

    public static Color get_RandomColor() {

         int r1 = get_Random();

         int g1 = get_Random();

         int b1 = get_Random();

        Color c1 = new Color(r1,g1,b1);

         return c1;

     }

    // get random value

    public static int get_Random() {

         return (int)(Math.random() * 255) + 1;

     }

}

Add a comment
Know the answer?
Add Answer to:
Please use JAVA Create an additional drawing panel at least 400 x 400. On it, draw filled-in shap...
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
  • 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...

  • 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...

  • 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...

  • Use WebGL to write a program that plays tic-tac-toe. The program should begin by drawing the...

    Use WebGL to write a program that plays tic-tac-toe. The program should begin by drawing the game board (two vertical lines and two horizontal lines). When a player left-clicks on an open space, the program should draw an “X” in that square. When a player right-clicks on an open space, the program should draw an “O” in that square. The Xs must be different colors from the Os. Both of those colors must be different from the lines making the...

  • Java Painter Class This is the class that will contain main. Main will create a new...

    Java Painter Class This is the class that will contain main. Main will create a new Painter object - and this is the only thing it will do. Most of the work is done in Painter’s constructor. The Painter class should extend JFrame in its constructor.  Recall that you will want to set its size and the default close operation. You will also want to create an overall holder JPanel to add the various components to. It is this JPanel that...

  • Modify the NervousShapes program so that it displays equilateral triangles as well as circles and rectangles....

    Modify the NervousShapes program so that it displays equilateral triangles as well as circles and rectangles. You will need to define a Triangle class containing a single instance variable, representing the length of one of the triangle’s sides. Have the program create circles, rectangles, and triangles with equal probability. Circle and Rectangle is done, please comment on your methods so i can understand */ package NervousShapes; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import javax.swing.*; import javax.swing.event.*; public class...

  • Java Programming .zip or .jar with 4 files: Shape.java, Square.java, TSquare.java, Triangle.java In this homework, you w...

    Java Programming .zip or .jar with 4 files: Shape.java, Square.java, TSquare.java, Triangle.java In this homework, you will build the below hierarchy: Overview: You will implement the supplier code: Shape, Square, TSquare, and Triangle, which will be used by the Homework7Main program. This program will use the DrawingPanel to draw these objects onto a canvas. Specification: You will take advantage of inheritance with using a super class, Shape.java. (below) Shape is an abstract class, which means it can be extended, but...

  • import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow...

    import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow for simple graphical drawing on a canvas. * This is a modification of the general purpose Canvas, specially made for * the BlueJ "shapes" example. * * @author: Bruce Quig * @author: Michael Kolling (mik) * Minor changes to canvas dimensions by William Smith 6/4/2012 * * @version: 1.6 (shapes) */ public class Canvas { // Note: The implementation of this class (specifically the...

  • import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow...

    import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow for simple graphical drawing on a canvas. * This is a modification of the general purpose Canvas, specially made for * the BlueJ "shapes" example. * * @author: Bruce Quig * @author: Michael Kolling (mik) * Minor changes to canvas dimensions by William Smith 6/4/2012 * * @version: 1.6 (shapes) */ public class Canvas { // Note: The implementation of this class (specifically the...

  • ##JAVA## about a GUI program (see screenshot below) that permits the user to create, save, and load polygons that are displayed (both hollow and filled) in a GUI. The features and operations required...

    ##JAVA## about a GUI program (see screenshot below) that permits the user to create, save, and load polygons that are displayed (both hollow and filled) in a GUI. The features and operations required by the GUI program include: 1. The program starts with an empty (no vertices) polygon set with a randomly generated color. The drawing area is set to be initially square and should have a black background. ------------------------------------------------------------------------------------------------ 2. The left mouse button lets you begin building a...

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