Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Need help with creating penguin applet

  1. #1
    Junior Member
    Join Date
    Oct 2020
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile Need help with creating penguin applet

    Hi. I got a project where I have to make an applet of any picture or object. I choose a penguin. I am basically almost done, however, I need help on how to create his beak and arms. I just need to know what method to use to make and set the arms and beak.


    For reference, I am trying to make this picture https://imgur.com/a/95E22Is

    This is the code

     
    import java.awt.*; // Imports art utils
    import javax.swing.*; //Imports program used to show graphics
    public class Penguin extends Canvas // Class name and allows class to be used elsewhere
    {
      public static void main (String [] args) //Main method
      {
        JFrame frame = new JFrame("Penguin"); //Creates a new JFrame (method used to display code)
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Makes the code exit when the exit button is pressed
        Canvas canvas = new Penguin(); //Creates new canvas
        canvas.setSize(600, 600); //Sets canvas size
        canvas.setBackground(Color.cyan);//Sets canvas background
        frame.add(canvas);// Adds canvas to frame to show
        frame.pack();
        frame.setVisible(true); //Allows canvas to show
     
      }
     
      public void paint(Graphics g) //Method used to create the graphics 
     
      {
        //All declerations made here store a color in a variable through RGB values
        Color e = new Color ( 0,0,0);
        Color f = new Color ( 255, 153, 0);
        Color i = new Color ( 217, 217, 217);
        Color h = new Color ( 255, 255, 255);
     
        g.setColor (e); //Creates the penguins body
        g.fillOval (90,142, 400,400); 
     
        g.setColor (i); //Adds the penguins stomach and shadow
        g.fillOval (137,275, 305,260);
        g.setColor (h);
        g.fillOval (165,275, 250,250); 
     
        //Makes penguins feet
        g.setColor (f);
        g.fillOval (307,490, 190,75); 
        g.setColor (f);
        g.fillOval (90,490, 190,75);
     
        g.setColor (h); //Makes penguins eyes
        g.fillOval (190,152, 105,120); //Left eye
        g.setColor (h);
        g.fillOval (300,173, 135,100); //Right eye
     
        g.setColor (e);//Makes penguins pupils
        g.fillOval (304,205, 30,40);//Left pupil
        g.setColor (e);
        g.fillOval (245,190, 50,60); //Right pupil
     
     
     
     
     
      }//End of paint
    }
    Last edited by shorba14; October 31st, 2020 at 01:12 PM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need help with creating penguin applet

    What shapes are needed to draw the arms and beak?

    Look at the drawPolygon method to draw custom shapes.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    shorba14 (October 31st, 2020)

  4. #3
    Junior Member
    Join Date
    Oct 2020
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need help with creating penguin applet

    I was thinking the arms could be right-angled triangles and the beak would be an equilateral with an arc on top. basically like the image I linked. ill use that method

  5. #4
    Junior Member
    Join Date
    Oct 2020
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need help with creating penguin applet

    yeah thanks i finished it now

Similar Threads

  1. Creating a cube applet
    By ATB in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 6th, 2014, 03:45 PM
  2. creating Frame objects in an Applet
    By vk2goh in forum AWT / Java Swing
    Replies: 1
    Last Post: May 30th, 2012, 07:04 AM
  3. Creating an Applet program using JTextFields, JLabel, Jbutton.
    By Maxly in forum Java Theory & Questions
    Replies: 1
    Last Post: March 9th, 2012, 02:39 PM
  4. Waddle the Java Jedi Penguin needs help with assignment.
    By javapenguin in forum What's Wrong With My Code?
    Replies: 25
    Last Post: September 20th, 2010, 05:31 PM
  5. Creating a threaded applet
    By mjpam in forum Java Applets
    Replies: 22
    Last Post: August 11th, 2010, 06:37 PM