Hi everyone! I have a homework problem and I can't seem to get it to work.
We're supposed to make a snowman melt when you click on it with the mouse, but my snowman refuses to melt. I know it's a problem with the mousePressed method in the MeltingSnowman class because it even refuses to print out the line, so it's not a fault with the toMeltMove method.
Anyway, here it goes:
SnowmanCartoon.java
import wheels.users.*;
public class SnowmanCartoon extends Frame{
private MeltingSnowman snowman;
private Ellipse sun;
public SnowmanCartoon(){
sun = new Ellipse(java.awt.Color.YELLOW);
sun.setSize(150,150);
sun.setLocation(520,10);
snowman = new MeltingSnowman();
}
public static void main (String[] args){
SnowmanCartoon app = new SnowmanCartoon();
}
}
Snowman.java
import wheels.users.*;
public class Snowman{
protected Ellipse body, head, leftEye, rightEye;
protected int b1, b2, h1, h2;
protected int bx, by, hx, hy;
protected int y;
protected Rectangle hat1, hat2;
protected int z;
public Snowman(){
b1 = 180;
b2 = 180;
h1 = 100;
h2 = 100;
bx = 50;
by = 300;
hx = 90;
hy = 200;
y = 230;
head = new Ellipse(java.awt.Color.WHITE);
head.setFrameColor(java.awt.Color.BLACK);
head.setSize(h1, h2);
head.setLocation(hx, hy);
body = new Ellipse(java.awt.Color.WHITE);
body.setFrameColor(java.awt.Color.BLACK);
body.setSize(b1, b2);
body.setLocation(bx, by);
leftEye = new Ellipse(java.awt.Color.BLACK);
leftEye.setSize(10,10);
leftEye.setLocation(120, y);
rightEye = new Ellipse(java.awt.Color.BLACK);
rightEye.setSize(10,10);
rightEye.setLocation(150, y);
z = 140;
hat1 = new Rectangle(java.awt.Color.black);
hat1.setSize(90,15);
hat1.setLocation(95, z + 50);
hat2 = new Rectangle(java.awt.Color.BLACK);
hat2.setSize(60,60);
hat2.setLocation(110, z);
}
}
MeltingSnowman.java
import wheels.users.*;
public class MeltingSnowman extends Snowman{
public void toMeltMove(int g, int h, int j, int k, int l, int m, int n, int p, int y, int z){
while ((g > 0 && h > 0) || (j > 0 && k > 0)){
try {
g = g - 2;
h = h - 2;
j = j - 2;
k = k - 2;
body.setSize(g - 2 , h - 2);
head.setSize(j - 2, k - 2);
l = l + 1;
m = m + 2;
n = n + 1;
p = p + 4;
body.setLocation(l + 1, m + 2);
head.setLocation(n + 1, p + 4);
y = y + 2;
leftEye.setLocation(120, y + 2);
rightEye.setLocation(150, y + 2);
z = z + 3;
hat1.setLocation(95, z + 50);
hat2.setLocation(110, z);
Thread.currentThread().sleep(250);
}
catch (InterruptedException e){
y = 400;
leftEye.setLocation(120, y);
rightEye.setLocation(150, y);
}
}
}
public void mousePressed(java.awt.event.MouseEvent e){
//public MeltingSnowman(){
System.out.println("boo");
this.toMeltMove(b1, b2, h1, h2, bx, by, hx, hy, y, z);
}
}
The files imported are from the wheels class (and subclasses), which you can find http://cs.stuy.edu/common/index.py?root=apcs&basename=code&mod=code&dir=src/ml1x/platek/wheelsDocs.
Thanks for any help! :)