Question

In: Computer Science

Make a java program of Mickey I have the starter program but I need to add...

Make a java program of Mickey I have the starter program but I need to add eyes and a smile to it.

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import javax.swing.JFrame;

public class Mickey extends Canvas {

public static void main(String[] args) {
JFrame frame = new JFrame("Mickey Mouse");
Canvas canvas = new Mickey();
canvas.setSize(400, 400);
canvas.setBackground(Color.white);
frame.add(canvas);
frame.pack();
frame.setVisible(true);
}

public void paint(Graphics g) {
Rectangle bb = new Rectangle(100, 100, 200, 200);
mickey(g, bb);
}

public void boxOval(Graphics g, Rectangle bb) {
g.fillOval(bb.x, bb.y, bb.width, bb.height);
g.drawArc(130, 180, 50, 20, 180, 180);
}

public void mickey(Graphics g, Rectangle bb) {
boxOval(g, bb);

int dx = bb.width / 2;
int dy = bb.height / 2;
Rectangle half = new Rectangle(bb.x, bb.y, dx, dy);

half.translate(-dx / 2, -dy / 2);
boxOval(g, half);

half.translate(dx * 2, 0);
boxOval(g, half);
}

}

Solutions

Expert Solution


As per the problem statement I have solve the problem. Please let me know if you have any doubts or you want me to modify the answer. And if you find this answer useful then don't forget to rate my answer as thumps up. Thank you! :)


//Mickey.java

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JComponent;
import javax.swing.JFrame;

//Class Mickey
public class Mickey extends JComponent {

    static final int WIDTH = 750;
    static final int HEIGHT = 750;
    String title = "Mickey Mouse";
    Color faceskin = new Color(239, 195, 129);

    //constructor
    public Mickey() {

        //frame
        JFrame frame = new JFrame(title);

        // sets the size of my game
        this.setPreferredSize(new Dimension(WIDTH, HEIGHT));
        // adds the game to the window
        frame.add(this);

        frame.setResizable(false);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);

    }

    //paint component
    @Override
    public void paintComponent(Graphics graphics) {
        graphics.clearRect(0, 0, WIDTH, HEIGHT);
        graphics.setColor(Color.BLACK);
        graphics.fillOval(125, 200, 500, 450);
        //ears
        graphics.fillOval(45, 30, 275, 275);
        graphics.fillOval(400, 30, 275, 275);

       //face
        graphics.setColor(faceskin);
        graphics.fillOval(125, 450, 500, 200);
        graphics.setColor(Color.BLACK);
        graphics.drawOval(125, 450, 500, 200);
        graphics.setColor(faceskin);
        graphics.fillOval(200, 250, 200, 300);
        graphics.fillOval(350, 250, 200, 300);
        graphics.fillOval(275, 550, 200, 150);
        graphics.setColor(Color.BLACK);
        graphics.drawArc(275, 550, 200, 150, 180, 180);
        //eyes
        graphics.setColor(Color.WHITE);
        graphics.fillOval(250, 310, 100, 160);
        graphics.fillOval(400, 310, 100, 160);
        graphics.setColor(Color.BLACK);
        graphics.drawOval(250, 310, 100, 160);
        graphics.drawOval(400, 310, 100, 160);
        //pupils
        graphics.setColor(Color.BLACK);
        graphics.setColor(Color.WHITE);
        //nose
        graphics.setColor(Color.BLACK);
        graphics.setColor(Color.WHITE);
        //mouth
        graphics.setColor(Color.BLACK);
        graphics.fillArc(300, 525, 150, 150, 180, 180);
        graphics.setColor(Color.PINK);
        graphics.fillArc(325, 560, 100, 100, 180, 180);
        graphics.setColor(Color.RED);
        graphics.fillOval(345, 630, 60, 30);

}


    public static void main(String[] args) {

        //instatiate the class
        Mickey mickey = new Mickey();
    }
}


Related Solutions

Using java, I need to make a program that reverses a file. The program will read...
Using java, I need to make a program that reverses a file. The program will read the text file character by character, push the characters into a stack, then pop the characters into a new text file (with each character in revers order) EX: Hello World                       eyB       Bye            becomes    dlroW olleH I have the Stack and the Linked List part of this taken care of, I'm just having trouble connecting the stack and the text file together and...
I need to make JAVA program that calculates the area of a brick of a specific...
I need to make JAVA program that calculates the area of a brick of a specific color. I have class Brick with the following UML: String color int number int length int width I made methods: getColor(), getNumber(), getLength(), getWidth() in the class Brick So it starts like this: ##### public Brick(String color, int number, int length, int width) { this.color = color; this.number = number; this.length = length; this.width = width;    }   public String toString() {   return number...
So I need to make a java program that reverse or replace first or lastchar or...
So I need to make a java program that reverse or replace first or lastchar or remove char from user's string input. length, concat, charAt, substring, and equals (or equalsIgnoreCase) thses are the string method that only I can use for example if user put asdf asdf and chose reverse input should be fdsa fdsa if user put asdf asdf and chose replace first a with b input should be bsdf asdf if user put asdf asdf and chose remove...
Make a package a5. To this package, add SearchTest.java (Links to an external site.) with starter...
Make a package a5. To this package, add SearchTest.java (Links to an external site.) with starter code for the assignment. You will want to carefully read the comments in this file to see where you need to add code. Search Experiment In this assignment you will measure the relative performance of binary search and sequential search on different length arrays. The basic idea is to make an array of random values, sort them, and then compare the performance of binary...
i need a pseudocode for a program in java that will convert dollars into euros and...
i need a pseudocode for a program in java that will convert dollars into euros and japanese yen using the print and prinln methods an if, if -else, statement a switch statement a while statement utilizes the file class uses the random class and random number generator and uses at least three methods other than main
I need to add the following to this program 1) Alphabetically sort the list of entries...
I need to add the following to this program 1) Alphabetically sort the list of entries by name (first or last). 2) Find a phone number for a given name. 3) Randomly select a friend from the phonebook for you to call. 4) Delete everyone from the phonebook at the same time. #include <stdio.h> #include<string.h> #include <ctype.h> #include<stdlib.h> typedef struct contact { char firstname[20]; char lastname[20]; char phoneNumber[15]; struct contact * next; struct contact * prev; }contact; typedef enum {...
I need to add this checkpoint to an existing code that i have in python Checkpoint...
I need to add this checkpoint to an existing code that i have in python Checkpoint 1: Once you have created and tested the Bank Account Class create subclasses to the BankAccount class. There should be two subclasses, CheckingAccount and SavingsAccount. You should add interest_rate to the parent BankAccount class. To the CheckingAccount add variables called per_check_fee default to false and allow_overdraft default to True. To SavingsAccount add the variable transactions_per_month, default it to 5. Create instances of CheckingAccount and...
write a java program of mickey mouse it can be simple with just ears face eyes...
write a java program of mickey mouse it can be simple with just ears face eyes and mouth
My Java program keeps "running." I know I need to close a "loop" but I can't...
My Java program keeps "running." I know I need to close a "loop" but I can't find it. I'm learning how to code. This is confusing for me. import java.util.Scanner; import java.util.ArrayList; public class SteppingStone4_Loops {    public static void main(String[] args) { Scanner scnr = new Scanner(System.in); String recipeName = ""; ArrayList<String> ingredientList = new ArrayList(); String newIngredient = ""; boolean addMoreIngredients = true; System.out.println("Please enter the recipe name: "); recipeName = scnr.nextLine();    do {    System.out.println("Would you...
Please add to this Python, Guess My Number Program. Add code to the program to make...
Please add to this Python, Guess My Number Program. Add code to the program to make it ask the user for his/her name and then greet that user by their name. Please add code comments throughout the rest of the program If possible or where you add in the code to make it ask the name and greet them before the program begins. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT