I'm learning how to use color in an image, but I'm having some trouble. This is just a test, but I have a ball and when I click this ball I want it to turn black. This is the code:
All help appreciated.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; /** * Write a description of class Ball here. * * @author (your name) * @version (a version number or a date) */ public class Ball extends Actor { private Color color2 = Color.BLACK; /** * Act - do whatever the Ball wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { paint(); } public void paint() { if(Greenfoot.mouseClicked(this)) { GreenfootImage img = new GreenfootImage(20,100); img.setColor(color2); setImage(img); } } }