I'm trying to make a snowman in BlueJ: Could someone help?

Question:
I’m using BlueJ (in a slightly outdated version) to make a snowman in Java Applets (cause why not) but I’d like some assistance making it. Could anyone help?

import java.awt.*;
import javax.swing.*;

public class snowman extends JApplet
{
    public void paint(Graphics g)
    {
        g.setColor(Color.gray);
        g.fillOval(140,60,60,60);  
        g.fillOval(120,110,100,100);
        g.fillOval(95,160,150,150);
        
    }
}

Are you using C++ or Java?

Aww crap. I meant Java - good catch.

You already started correctly you just need to create the rest of body parts.
For example you can use the first class as the main body (head, middle, base) and continue with the other parts

import java.awt.*;
import javax.swing.*;

public class Snowman extends JApplet
{
    public void paint(Graphics g)
    {
        // Here you set the main body
        g.setColor(Color.white); //I changed to white cause, you know, snowmans are white
        g.fillOval(140,60,60,60);  // can be the head
        g.fillOval(120,110,100,100); //  can be the middle
        g.fillOval(95,210,150,150); //  can be the base
        
        //  After that you continue to do the other parts, for example, the eyes are black so you use
        g.setColor(Color.black);
        g.fillOval(155, 80, 10, 10); // left eye
        g.fillOval(175, 80, 10, 10); // right eye
        
       // and continue with the rest, like the nose (orange), and it can be a polygon (g.fillPolygon)
    }
}
1 Like

Thanks for the help! I just got back from a trip so I forgot how the coordinate pane and everything works. My current list of things to add is as follows:

  1. Arms
  2. Eyes
  3. Mouth and Nose
  4. Buttons

Arms you can use g.drawLine
Eyes you can use g.fillOval
Nose you can use g.fillPolygon
Mouth I think arc is enough g.drawArc
And buttons oval again.

1 Like

Yeah. It’s just the coordinates that always mess me up 'cause the coordinate pane is wonky.

Try this:

// Body of the snowman
g.setColor(Color.white);
g.fillOval(140, 60, 60, 60);  // head
g.fillOval(120, 110, 100, 100); // middle
g.fillOval(95, 210, 150, 150); // base

// Eyes
g.setColor(Color.black);
g.fillOval(155, 80, 10, 10); // left eye
g.fillOval(175, 80, 10, 10); // right eye

// Nose
g.setColor(Color.orange);
g.fillPolygon(new int[]{165, 175, 165}, new int[]{90, 95, 100}, 3);

// Mouth
g.setColor(Color.black);
g.drawArc(155, 100, 30, 10, -30, -120);

// Buttons
g.fillOval(160, 135, 10, 10);
g.fillOval(160, 155, 10, 10);
g.fillOval(160, 175, 10, 10);

// Arms (choose what you find more interesting)
g.setColor(Color.black); 
g.drawLine(95, 130, 70, 150); // Left arm - upper part
g.drawLine(70, 150, 55, 140); // Left arm - lower part
g.drawLine(245, 130, 270, 150); // Right arm - upper part
g.drawLine(270, 150, 285, 140); // Right arm - lower part

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.