I'm having issues with basically moving the snowman itself. I know I have to repaint image in a different position, but I tried and failed. The snowman always end up having a line of color and shape following it as an aftereffect.
Can anyone help me out on how to do this? Then I can actually start moving on finally ~_~
import jpb.*;
import java.awt.*;
public class SnowMan {
public static void main (String []args) {
DrawableFrame df = new DrawableFrame("SnowMan");
df.show();
df.setSize(500,500);
Graphics g = df.getGraphicsContext();
g.setColor(Color.green); //grass
g.fillRect(0, 400, 500, 500);
g.setColor(Color.black); //sky
g.fillRect(1,1,500,400);
Color brown = new Color(128, 64, 0);
g.setColor(brown); //ground
g.fillRect(0, 480, 499, 300);
g.setColor(Color.darkGray); //moon
g.fillOval(0,20, 170, 170);
g.setColor(Color.lightGray);
g.drawOval(30, 50, 10, 10);
g.drawOval(50, 70, 20, 20);
g.drawOval(30, 90, 10, 10);
g.drawOval(100, 70, 20, 20);
g.drawOval(40, 150, 10, 10);
g.drawOval(60, 100, 20, 20);
g.drawOval(30, 90, 10, 10);
g.drawOval(122, 150, 20, 20);
g.drawOval(120, 114, 30, 30);
g.drawOval(90, 100, 10, 10);
g.drawLine(100, 200, 120, 204); //haze
g.drawLine(155, 160, 170, 165);
g.drawLine(168, 140, 178, 150);
g.drawLine(176, 130, 190, 130);
g.drawLine(178, 110, 190, 110);
g.drawLine(170, 90, 190, 90);
g.drawLine(168, 70, 188, 70);
g.drawLine(170, 60, 180, 50);
g.setColor(Color.blue); // ground grass
g.setColor(Color.lightGray); //snowman
g.fillOval(250,300, 150, 150);
g.fillOval(268,200, 110, 110);
g.setColor(Color.white);
g.fillOval(292,140, 70, 70);
g.setColor(Color.lightGray); //spacesuit
g.drawOval(292,140, 70, 70);
g.drawOval(295,140, 70, 70);
g.drawOval(294,140, 70, 70);
g.drawOval(293,140, 70, 70);
g.drawOval(296,140, 70, 70);
g.drawOval(297,140, 70, 70);
g.drawOval(298,140, 70, 70);
g.drawOval(299,140, 70, 70);
g.setColor(Color.darkGray); //pocket
g.fillRect(280, 250, 26, 24);
g.setColor(Color.orange); //nose
int[] xC = {325, 330, 335};
int[] yC = {180, 200, 180};
g.fillPolygon(xC, yC, xC.length);
g.setColor(Color.black); //eyes
g.fillOval(318, 151, 10, 10);
g.fillOval(332, 151, 10, 10);
g.setColor(Color.blue);
for (int x = 0; x < 500; x += 20) { //grass patch in dirt
df.repaint();
try { Thread.sleep(100); }
catch (InterruptedException e) { }
for (int x1 = 0; x1 < 500; x1 += 20) {
df.repaint();
try { Thread.sleep(200); }
catch (InterruptedException e) { }
g.drawLine(x,498,x1,488); }
}
int count = 1;
do {
if( count % 2 == 0) {
g.setColor(Color.white);
g.fillOval(318, 151, 10, 10);
g.fillOval(332, 151, 10, 10);
} else {
g.setColor(Color.black); //eyes
g.fillOval(318, 151, 10, 10);
g.fillOval(332, 151, 10, 10);
}
try
{
g.fillOval(318, 151, 10, 10);
Thread.sleep(100);
}
catch(Exception e)
{
System.out.println(e);
}
count++;
df.repaint();
} while(count!=0);
}
}