This site requires JavaScript, please enable it in your browser!
Greenfoot back
koloughlin
koloughlin wrote ...

2016/11/27

Newtons Lab 2 Second Edition Cannot find symbol - class Color

koloughlin koloughlin

2016/11/27

#
I am trying to use the parameterized constructor in Newton's Lab2. The signature is: public Body(int size, double mass, Vector velocity, Color color) I enter something like 20, 20, new Vector (90, 1.0), new Color (12,12,12) and I get the error cannot find symbol - class Color. The color class has been imported. I have also tried the following parameters for color and they do not work either. new Color (12,12,12,1), color.Red, defaultColor. Scenario code: I did not change it from the second edition downloads import greenfoot.*; import java.awt.Color; import java.util.List; /** * A 'Body' is any kind of object in space that has a mass. It could be * a star, or a planet, or anything else that floats around in space. * * @author Michael Kölling * (Including improvements by J. Buhl.) * @version 1.0 */ public class Body extends SmoothMover { // constants private static final double GRAVITY = 5.8; private static final Color defaultColor = new Color(255, 216, 0); // fields private double mass; /** * Construct a Body with default size, mass, velocity and color. */ public Body() { this (20, 300, new Vector(0, 1.0), defaultColor); } /** * Construct a Body with a specified size, mass, velocity and color. */ public Body(int size, double mass, Vector velocity, Color color) { this.mass = mass; addToVelocity(velocity); GreenfootImage image = new GreenfootImage (size, size); //color = new Color (12,12,12); image.setColor (color); image.fillOval (0, 0, size-1, size-1); setImage (image); } I can send a snapshot of the error if needed.
danpost danpost

2016/11/27

#
The error is probably not in the Body class, but rather in your World subclass where you try to create a Body object. You can add an import line for the Color class or change 'new Color(12, 12, 12)' to 'new java.awt.Color(12, 12, 12)'.
You need to login to post a reply.