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...
I need to make this into a Java Code: Write a program that prompts the user...
I need to make this into a Java Code: Write a program that prompts the user for a double value representing a radius. You will use the radius to calculate: circleCircumference = 2πr circleArea = πr2 sphereArea = 4πr2 sphereVolume = 43πr3 You must use π as defined in the java.lang.Math class. Your prompt to the user to enter the number of days must be: Enter radius: Your output must be of the format: Circle Circumference = circleCircumference Circle Area...
Java - Text File to Arrays and output ------------------------------------------------------------------------------ I need to have a java program...
Java - Text File to Arrays and output ------------------------------------------------------------------------------ I need to have a java program read an "input.txt" file (like below) and store the information in an respective arrays. This input.txt file will look like below and will be stored in the same directory as the java file. The top line of the text represents the number of people in the group for example. the lines below it each represent the respective persons preferences in regards to the other...
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...
Read a text file into arrays and output - Java Program ------------------------------------------------------------------------------ I need to have...
Read a text file into arrays and output - Java Program ------------------------------------------------------------------------------ I need to have a java program read an "input.txt" file (like below) and store the information in an respective arrays. This input.txt file will look like below and will be stored in the same directory as the java file. The top line of the text represents the number of people in the group for example. the lines below it each represent the respective persons preferences in regards...
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...
Java Counter Program I can't get my program to add the number of times a number...
Java Counter Program I can't get my program to add the number of times a number was landed on for my if statements for No12 through No2. My Code: import java.util.Scanner; import java.util.Random;    import java.lang.*;       public class Dice    {               public static void main(String[] args)        {            Scanner in = new Scanner(System.in);            int Continue = 1;            //randomnum = new Random();           ...
**I need to make this program to make sure that the numbers are unique. In another...
**I need to make this program to make sure that the numbers are unique. In another word, if the number has been generated and appear early, it should continue to find the next number until the number is unique. Hint: use the array to check whether the number has been generated. #include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() { srand(time(NULL)); int n, low, high; cout << "Enter how many random numbers you would like to see:...
JAVA I need to make it that I can expand the stack for everytime a push...
JAVA I need to make it that I can expand the stack for everytime a push operation is performed that would normally cause an overflow, returning a false value. Should accompany 3 nodes initially. DriverStack.java public class DriverStack {    public static void main (String[] args) {    Stack s = new Stack(3); Listing l; Listing l1 = new Listing ("Bill", "1st Avenue", "123 4567"); Listing l2 = new Listing ("Alec", "2nd Avenue", "456 4567"); Listing l3 = new Listing...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT