Hey, I have been stuck with a screen saying that the world is being constructed... I tried closing the program and reopening it and restarting my pc but to no avail...
Here is my Background class:
here is my counter class:
here is my RecruitSkellyButton:
import lang.stride.*;
import java.util.*;
import greenfoot.*;
/**
*
*/
public class RecruitSkellyButton extends Buttons
{
GreenfootImage button = new GreenfootImage("RecruitSkellyButton1.png");
GreenfootImage buttonHighlighted = new GreenfootImage("RecruitSkellyButton1Highlighted.png");
GreenfootImage buttonGrayed = new GreenfootImage("RecruitSkellyButton1BlackandWhite.png");
private Counter counter;
public RecruitSkellyButton(Counter counter){
this.counter = counter;
button.scale(150,109);
buttonHighlighted.scale(150,109);
buttonGrayed.scale(150,109);
setImage(button);
}
/**
* Act - do whatever the Option1_Button wants to do. This method is called whenever the 'Act' or 'Run' button gets pressed in the environment. PLACEHOLDER FOR RECRUIT SKELLY BUTTON
*/
public void act()
{
Background world = (Background) getWorld();
Counter counter = world.getCounter();
if (counter.getValue() < 5) { //check if the counter has enough gold
setImage(buttonGrayed);
}
else if (counter.getValue() >= 5) {
RecruitSkelly skelly1 = new RecruitSkelly();
setImage(button);
if (Greenfoot.mouseMoved(this)) {
setImage(buttonHighlighted);
}
if (Greenfoot.mouseClicked(this)) {
Arrow arrow1 = new Arrow();
getWorld().addObject(arrow1, 163, 277);
Arrow arrow2 = new Arrow();
getWorld().addObject(arrow2, 163, 125);
}
}
}
}
Note: I get greeted with this terminal message whenever I open greenfoot:
2024-11-18 20:55:35.543 java +: chose IMKClient_Legacy
2024-11-18 20:55:35.544 java +: chose IMKInputSession_LegacyException in thread "AWT-EventQueue-0" java.lang.NegativeArraySizeException: -4
Any help would be appreciated!!
import lang.stride.*; import java.util.*; import greenfoot.*; /** * */ public class Background extends World { private Counter counter; /** * Constructor for objects of class Background. */ public Background() { super(848, 600, 1); prepare(); } /** * Prepare the world for the start of the program. * That is: create the initial objects and add them to the world. */ private void prepare() { GoldBar goldBar = new GoldBar(); addObject(goldBar,60,36); //Counter counter = new Counter(); //addObject(counter,155,53); //add the counter to the world counter = new Counter("Gold: "); addObject(counter, 155, 53); RecruitSkellyButton button1 = new RecruitSkellyButton(counter); addObject(button1, 414, 530); addObject(new SmallGoldBar(), 300, 300); SmallGoldBar smallGoldBar2 = new SmallGoldBar(); addObject(smallGoldBar2,297,400); SmallGoldBar smallGoldBar3 = new SmallGoldBar(); addObject(smallGoldBar3,424,296); SmallGoldBar smallGoldBar4 = new SmallGoldBar(); addObject(smallGoldBar4,422,401); SmallGoldBar smallGoldBar5 = new SmallGoldBar(); addObject(smallGoldBar5,563,291); SmallGoldBar smallGoldBar6 = new SmallGoldBar(); addObject(smallGoldBar6,562,401); } public Counter getCounter() { return counter; } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Counter here. * * @author (your name) * @version (a version number or a date) */ public class Counter extends Actor { //private static final Color transparent = new Color(0,0,0,0); private GreenfootImage background; private int value; //private int target; private String prefix; public Counter(String prefix) { background = new GreenfootImage("Counter.png"); background.scale(120,29); value = 0; this.prefix = prefix; updateImage(); } /** * Animate the display to count up (or down) to the current target value. */ /* public void act() { } */ public void add (int amount) { value += amount; updateImage(); } public int getValue() { return value; } public void updateImage() { GreenfootImage image = new GreenfootImage(background.getWidth(), background.getHeight()); // Draw the actual background image image.drawImage(background, 0, 0); // Create the text to display GreenfootImage text = new GreenfootImage(prefix + value + "g", 24, Color.BLACK, new Color(0, 0, 0, 0)); // Draw the text on top of the background image image.drawImage(text, (image.getWidth() - text.getWidth()) / 2, 4); // Position the text above the counter image setImage(image); // Set the actor's image to the new composite image } }