import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class MyWorld here. * * @author (your name) * @version (a version number or a date) */ public class Background extends World { /** * Constructor for objects of class MyWorld. * */ static final Color TRANS = new Color(0,0,0,0); String[] numButton = {"BUTTON 01","BUTTON 02","BUTTON 03","BUTTON 04","BUTTON 05"}; String[] numSounds = {"01 - Moonlight.wav","02 - Dangerous Woman.wav","03 - Be Alright.wav", "04 - Into You.wav","05 - Side to Side.wav"}; public Background() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(900, 600, 1); //addObject(btn01 = getNewButton("BUTTON 01"),200,100); //addObject(btn02 = getNewButton("BUTTON 02"),200,150); //addObject(btn03 = getNewButton("BUTTON 03"),200,200); } public void act() { createButton(); } private void createButton() { for(int i = 0; i<numButton.length; i++) for(int j = 0; j<numSounds.length; j++) { addObject(getNewButton(numButton[i]),200,i*50+100); addObject((numSounds[j]),400,j*50+100); } } public Actor getNewButton(String caption) { GreenfootImage base = new GreenfootImage(200,30); base.fill(); base.setColor(Color.BLUE); base.fillRect(3,3,194,24); GreenfootImage text = new GreenfootImage(caption, 24, Color.WHITE, TRANS); base.drawImage(text, 100-text.getWidth()/2, 15-text.getHeight()/2); base.setTransparency(128); Actor button = new SimpleActor(); button.setImage(base); return button; } }