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

2012/5/8

Is there a contrary from this code

1
2
3
4
5
trash1000 trash1000

2012/5/11

#
You do not have the method start() in your world. Define it (in your world) and the error is gone.
danpost danpost

2012/5/12

#
martijn13039 wrote...
hey danpost i´ve try your code but there is some error with private STring menuItem, I hope you can helpm me and I can understand the code much better
import greenfoot.*;
private String menuItem = "";
private boolean menuDone = false;

public class Start extends Actor
{

public void act()
{
    if (!menuDone && !"".equals(menuItem))
    {
        removeObjects(getObjects(Menu.class));
        
        menuDone = true;
    }
    
}

public void setMenuItem(String muItem)
{
    menuItem = muItem;
}
}
The problem with this code is the placement of your instance variables. The code should look like this:
import greenfoot.*;

public class Start extends Actor
{
    private String menuItem = "";
    private boolean menuDone = false;

    public void act()
    {
        if (!menuDone && !"".equals(menuItem))
        {
            removeObjects(getObjects(Menu.class));
            menuDone = true;
        }
    }    

    public void setMenuItem(String muItem)
    {
        menuItem = muItem;
    }
}
martijn13039 martijn13039

2012/5/12

#
there is an error with menu cannot find symbool class menu, but were need i make this method i hvae really no idea
davmac davmac

2012/5/12

#
menu cannot find symbool class menu
...
but were need i make this method i hvae really no idea
It says class Menu. It's a class, not a method, that the compiler wants.
martijn13039 martijn13039

2012/5/12

#
oow my fault but how can I make that
martijn13039 martijn13039

2012/5/12

#
Have you no idea plz say it than, maby I can ask somebody else than but thx that you have see a fault that I wrote :)
danpost danpost

2012/5/12

#
What do you have, as far as creating a menu or buttons? Please show your code. What objects have you created classes for?
martijn13039 martijn13039

2012/5/14

#
I got this 2 codes now but there is an error with both of the codes (and srry for my late respond, I was going way)
import greenfoot.*;

public class Start extends Actor
{
    private String menuItem = "";
    private boolean menuDone = false;

    public void act()
    {
        if (!menuDone && !"".equals(menuItem))
        {
            removeObjects(getObjects(Menu.class));
            menuDone = true;
        }
    }    

    public void setMenuItem(String muItem)
    {
        menuItem = muItem;
    }
}
import greenfoot.*;



public class Start extends Actor
{

String caption = "";

    public Start(String text)
    {
        caption = text;
        updateImage();
    }

    private void updateImage()
    {
        
    }

    public void act()
    {
        if (Greenfoot.mouseClicked(this))
        {
            World2 mw = (World2) getWorld();
            
            
            mw.setMenuItem(caption);
        }

}
}
danpost danpost

2012/5/15

#
You totally mis-placed the code I provided. See my post on 5/9/12; the last sentence before the code says to put it in the world class. Also, using 'Menu.class' was more of an example, though you did say it was a menu. Replace 'Menu.class' with 'Start.class'. If you have more than one class for menu related objects then add more 'removeObjects(getObjects(Class cls));' lines. You will need one for each type object related to the menu. Or if you have a super-class that contains all parts of the menu as subclasses, just change 'Menu.class' to the name of that class (don't forget to include the '.class' after the name).
martijn13039 martijn13039

2012/5/18

#
danpost first I will apologise me for my last respond again. I had make one supere class but there is still an error, this code I got now and there is an error on getobject there stay cannont find symbol- method getobjects(jave.lang.class<start>) I hope you got an idea
import greenfoot.*;

public class Start extends Actor
{
    public boolean Start;
    private String menuItem = "";
    private boolean menuDone = false;

    public void act()
    {
        if (!menuDone && !"".equals(menuItem))
        {
            removeObjects(getObjects(Start.class));
            menuDone = true;

            if (Greenfoot.mouseClicked(this))
            {
                World2 mw = (World2) getWorld();

                mw.setMenuItem(caption);
            }

        }
    }    

    public void setMenuItem(String muItem)
    {
        menuItem = muItem;
    }

    String caption = "";

    public Start(String text)
    {
        caption = text;
        updateImage();
    }

    private void updateImage()
    {

    }

}
trash1000 trash1000

2012/5/18

#
Both removeObjects() and getObjects() are methods of the class World.
getWorld().removeObjects(getWorld().getObjects(Start.class));
martijn13039 martijn13039

2012/5/18

#
now i got this but thee is an error setmenu
import greenfoot.*;

public class Start extends Actor
{
    public boolean Start;
    private String menuItem = "";
    private boolean menuDone = false;

    public void act()
    {
        if (!menuDone && !"".equals(menuItem))
        {
           getWorld().removeObjects(getWorld().getObjects(Start.class));  
            menuDone = true;

            if (Greenfoot.mouseClicked(this))
            {
                World2 mw = (World2) getWorld();

                mw.setMenuItem(caption);
            }

        }
    }    

    public void setMenuItem(String muItem)
    {
        menuItem = muItem;
    }

    String caption = "";

    public Start(String text)
    {
        caption = text;
        updateImage();
    }

    private void updateImage()
    {

    }

}
davmac davmac

2012/5/18

#
now i got this but thee is an error setmenu
What does that mean? If you got an error, at least say what the error message was and what line it's on.
martijn13039 martijn13039

2012/5/18

#
oow srry davmac I thaw i had post it but you right I for get it, I understand it is really annoying if people need help but don´t tell wat is wrong this is the thing that the error say on line 20 mw.setmenuitem, cannont find symbol- method setmenuitem(jave.lang.string) i hope you got an idea
trash1000 trash1000

2012/5/18

#
                World2 mw = (World2) getWorld();  
  
                mw.setMenuItem(caption);  
You try to call a method setMenuItem() in your subclass of world. From the error message it's obvious that you do not have this method in your world.
There are more replies on the next page.
1
2
3
4
5