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

2013/4/4

Choosing a bug color in Gridworld

ms20492 ms20492

2013/4/4

#
We're using Greenfoot for our AP CS gridworld simulation. I'm trying to decide if Greenfoot supports choosing a color for a bug. The standard gridworld distribution prompts you with a dropdown to choose a color when a bug is being constructed. The greenfoot version prompts with a blank drop down. Thanks!
dyanek dyanek

2013/8/25

#
I tried entering Color.GREEN, but get an error.
danpost danpost

2013/8/25

#
What error did you get? Show the code you are trying to make work.
dyanek dyanek

2013/8/25

#
See image below. I right click on bug and select new Bug(Color bugColor). The image is a screen shot of what happens when I supply a value for the parameter. Thanks, Don
danpost danpost

2013/8/25

#
Try entering 'java.awt.Color.GREEN' (without the quote marks).
dyanek dyanek

2013/8/26

#
That worked! Gotta admit, I never would have thought to try that. Why doesn't Color.Green work? Parameters of type int work just fine with an integer value provided. Thanks again! Don
danpost danpost

2013/8/26

#
int is a primitive type while Color is not. You need to inform the system where to find the Color class.
dyanek dyanek

2013/8/26

#
Hmm. That seems redundant since the Bug class imports java.awt.Color already. Is this a Greenfoot requirement or Gridworld? Will I need to do this with other object types too? Thanks again!
danpost danpost

2013/8/26

#
I am not that familiar with GridWorld, but it would seem that 'create object' is not a method in the Bug class (it is probably of the GridWorld class) and therefore having the import there would not be relevant. I am not sure that even if it was imported in the GridWorld class that you could shorten it to 'Color.GREEN'. Basically, any external class would have to reference in this way when manually performing actions like this.
You need to login to post a reply.