I'm so stuck on how to use a string of colors.
PlayerWorld world:
PlayMusicButton Actor Class:
import greenfoot.*; import java.awt.Color; import java.awt.Font; public class PlayerWorld extends World { private PlayMusicButton q; private PlayMusicButton[] playmusicbutton = new PlayMusicButton[5]; private static String[] soundFiles = {"Drive Me Home", "Get It On", "Hair", "Marry The Night", "Open Up Wide"}; private static String[] songNames = {"Drive Me Home", "Get It On", "Hair", "Marry The Night", "Open Up Wide"}; private static String[] colors = {"Color.yellow", "Color.white", "Color.lightGray", "Color.pink", "Color.cyan"}; public PlayerWorld() { super(600, 400, 1); addObject(new StopButton(), 480, 200); for(int i = 0; i < 5; i++) { addObject(new PlayMusicButton(soundFiles[i], songNames[i], colors[i]), 200, 50 + i * 75); } } }
import greenfoot.*; import java.awt.Color; import java.awt.Font; public class PlayMusicButton extends Actor { private String soundFiles; private String songNames; private String colors; private static final int WIDTH = 220; private static final int HEIGHT = 40; private boolean selected; public PlayMusicButton(String soundFiles, String songNames, String colors) { this.soundFiles = soundFiles; this.songNames = songNames; this.colors = colors; selected = false; makeImage(); } public void act() { checkMouseClick(); } private void checkMouseClick() { if(!selected && Greenfoot.mouseClicked(this)) { GreenfootImage image = new GreenfootImage(WIDTH, HEIGHT); image.setColor(colors); image.fillRect(0, 0, WIDTH, HEIGHT); image.setColor(Color.BLACK); image.drawRect(0, 0, WIDTH-1, HEIGHT-1); image.setColor(Color.BLACK); Font font = image.getFont(); image.setFont(new Font("Courier New", Font.BOLD, 22)); image.drawString("" + songNames, 12, 22); setImage(image); selected = true; Greenfoot.playSound(soundFiles + ".mp3"); } if(selected && !Greenfoot.mouseClicked(this)) { GreenfootImage image = new GreenfootImage(WIDTH, HEIGHT); image.setColor(colors); image.fillRect(0, 0, WIDTH, HEIGHT); image.setColor(Color.BLACK); image.drawRect(0, 0, WIDTH-1, HEIGHT-1); image.setColor(Color.BLACK); Font font = image.getFont(); image.setFont(new Font("Courier New", Font.PLAIN, 22)); image.drawString("" + songNames, 12, 22); setImage(image); selected = true; Greenfoot.playSound(soundFiles + ".mp3"); selected = false; } } public boolean isSelected() { return selected; } private void makeImage() { GreenfootImage image = new GreenfootImage(WIDTH, HEIGHT); image.setColor(colors); image.fillRect(0, 0, WIDTH, HEIGHT); image.setColor(Color.BLACK); image.drawRect(0, 0, WIDTH-1, HEIGHT-1); image.setColor(Color.BLACK); Font font = image.getFont(); image.setFont(new Font("Courier New", Font.PLAIN, 22)); image.drawString("" + songNames, 12, 22); setImage(image); } }