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

2013/11/23

Mouse click over certain area?

1
2
danpost danpost

2013/12/4

#
Yedya wrote...
Throwing out an error,not a statment
Please elaborate. Restate any problem you have at this point.
Yedya Yedya

2013/12/4

#
danpost danpost

2013/12/4

#
Is 'Reverb2' the name of an object of the class 'Revert2'? or is 'Reverb2' a field name declared near the beginning of the class? (if so, show the field declaration statement) Also, remove the outer set of parenthesis, '( )', from the line.
Yedya Yedya

2013/12/4

#
Sorry reverb2 is the name of the class,im not using an object
danpost danpost

2013/12/4

#
Well, 'setImage' can only be used on an Actor instance (an Actor object), not on an Actor class. Only 'static' methods can be called by using the class name and 'setImage' is a non-static method.
Yedya Yedya

2013/12/4

#
so if i make an object within the class and the refer to the object?
danpost danpost

2013/12/4

#
If you are trying to change the image of an object that is already in your world, you need to refer to that object (not a new one). If you only have one of that type object in your world, you can use: 'getWorld().getObjects(Reverb2.class).get(0)' to refer to that object; however, it will be know only as an Object type at this point. Casting it as an Actor type would be sufficient to change its image using 'setImage' (as that method resides in the 'Actor' class).
Actor reverb2 = (Actor)getWorld().getObjects(Reverb2.class).get(0);
revert2.setImage(/* image or image filename */);
Yedya Yedya

2013/12/4

#
edit~ did see the post will try^ I don't have any objects,all I have is classes with images set to the class.If I make an object within a class and refer to it when like so ('actorReferenceName.setImage("imageFileName.png" will it work?
danpost danpost

2013/12/4

#
Yedya wrote...
I don't have any objects,all I have is classes with images set to the class.If I make an object within a class and refer to it when like so ('actorReferenceName.setImage("imageFileName.png" will it work?
Please show the code for your subclass of World, so I can correct you on this.
Yedya Yedya

2013/12/4

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class nkbkj here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class background extends World
{
    
 
    public background()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(800, 650, 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()
    {

        C c = new C();
        addObject(c, 72, 20);
        //  B b = new B();
        //    addObject(b, 76, 66);
        A a = new A();
        addObject(a, 84, 119);
        G g = new G();
        addObject(g, 91, 176);

        E e = new E();
        addObject(e, 96, 272);
        D d = new D();
        addObject(d, 108, 320);
        c.setLocation(63, 13);
        //  b.setLocation(63, 43);
        a.setLocation(63, 73);
        g.setLocation(62, 103);
        g.setLocation(63, 103);

        e.setLocation(63, 163);
        d.setLocation(63, 193);

        gSharp gsharp = new gSharp();
        addObject(gsharp, 42, 93);
        aSharp asharp = new aSharp();
        addObject(asharp, 40, 62);
        asharp.setLocation(40, 55);
        gsharp.setLocation(36, 88);
        asharp.setLocation(37, 55);
        fSharp fsharp = new fSharp();
        addObject(fsharp, 41, 124);
        fsharp.setLocation(37, 120);
        asharp.setLocation(36, 57);
        dSharp dsharp = new dSharp();
        addObject(dsharp, 460, 280);
        removeObject(dsharp);
        C c2 = new C();
        addObject(c2, 69, 230);
        c2.setLocation(63, 223);
        dSharp dsharp2 = new dSharp();
        addObject(dsharp2, 43, 183);
        dsharp2.setLocation(37, 179);
        cSharp csharp = new cSharp();
        addObject(csharp, 42, 217);
        csharp.setLocation(37, 210);
        //  B b2 = new B();
        //  addObject(b2, 69, 260);
        //  b2.setLocation(63, 253);
        A a2 = new A();
        addObject(a2, 69, 290);
        a2.setLocation(63, 283);
        G g2 = new G();
        addObject(g2, 69, 320);
        g2.setLocation(64, 318);
        g2.setLocation(63, 313);
        F f2 = new F();
        addObject(f2, 69, 350);
        f2.setLocation(63, 344);
        f2.setLocation(64, 344);
        f2.setLocation(63, 344);
        f2.setLocation(63, 343);
        E e2 = new E();
        addObject(e2, 69, 380);
        e2.setLocation(57, 378);
        e2.setLocation(63, 373);
        D d2 = new D();
        addObject(d2, 69, 410);
        d2.setLocation(60, 401);
        d2.setLocation(64, 403);
        d2.setLocation(64, 403);
        d2.setLocation(65, 401);
        d2.setLocation(63, 403);
        aSharp asharp2 = new aSharp();
        addObject(asharp2, 40, 275);
        asharp2.setLocation(40, 272);
        asharp2.setLocation(39, 272);
        asharp2.setLocation(38, 271);
        gSharp gsharp2 = new gSharp();
        addObject(gsharp2, 37, 301);
        fSharp fsharp2 = new fSharp();
        addObject(fsharp2, 52, 339);
        dSharp dsharp3 = new dSharp();
        addObject(dsharp3, 77, 387);
        asharp2.setLocation(35, 266);
        gsharp2.setLocation(36, 297);
        fsharp2.setLocation(36, 327);
        dsharp3.setLocation(38, 385);
        cSharp csharp2 = new cSharp();
        addObject(csharp2, 41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        csharp2.setLocation(41, 8);
        removeObject(csharp2);
        c2.setLocation(236, 221);
        C2 c22 = new C2();
        addObject(c22, 393, 275);
        removeObject(c22);
        C2 c23 = new C2();
        addObject(c23, 242, 295);
        csharp.setLocation(266, 166);
        removeObject(c2);
        c23.setLocation(62, 223);
        c23.setLocation(63, 223);
        csharp.setLocation(38, 208);
        c23.setLocation(215, 234);
        csharp.setLocation(252, 194);
        c23.setLocation(63, 223);
        csharp.setLocation(41, 208);
        csharp.setLocation(35, 208);
        //   b2.setLocation(238, 247);
        B2 b22 = new B2();
        addObject(b22, 69, 260);
        b22.setLocation(57, 255);
        b22.setLocation(58, 254);
        b22.setLocation(59, 254);
        b22.setLocation(63, 256);
        b22.setLocation(63, 253);
        aSharp2 asharp22 = new aSharp2();
        addObject(asharp22, 331, 203);
        csharp.setLocation(437, 318);
        asharp22.setLocation(36, 209);
        asharp22.setLocation(351, 199);
        csharp.setLocation(37, 208);
        removeObject(b22);
        B2 b23 = new B2();
        addObject(b23, 65, 259);
        b23.setLocation(63, 253);
        cSharp csharp3 = new cSharp();
        addObject(csharp3, 463, 251);
        csharp.setLocation(235, 173);
        removeObject(csharp);
        csharp3.setLocation(39, 209);
        asharp22.setLocation(152, 198);
        //    b2.setLocation(215, 286);
        a2.setLocation(279, 368);
        removeObject(a2);
        removeObject(asharp2);
        removeObject(gsharp2);
        removeObject(g2);
        removeObject(f2);
        removeObject(fsharp2);
        removeObject(e2);
        A2 a22 = new A2();
        addObject(a22, 71, 295);
        G2 g22 = new G2();
        addObject(g22, 169, 342);
        F2 f22 = new F2();
        addObject(f22, 339, 378);
        a22.setLocation(63, 283);
        g22.setLocation(63, 312);
        g22.setLocation(63, 313);
        f22.setLocation(63, 343);
        E2 e22 = new E2();
        addObject(e22, 520, 468);
        D2 d22 = new D2();
        addObject(d22, 531, 531);
        e22.setLocation(62, 373);
        dsharp3.setLocation(263, 423);
        removeObject(dsharp3);
        removeObject(d2);
        e22.setLocation(63, 373);
        d22.setLocation(63, 403);
        asharp22.setLocation(204, 194);
        removeObject(asharp22);
        //    removeObject(b2);
        aSharp2 asharp23 = new aSharp2();
        addObject(asharp23, 44, 273);
        gSharp2 gsharp22 = new gSharp2();
        addObject(gsharp22, 52, 320);
        fSharp2 fsharp22 = new fSharp2();
        addObject(fsharp22, 67, 366);
        asharp23.setLocation(38, 267);
        dsharp2.setLocation(39, 179);
        gsharp22.setLocation(38, 298);
        fsharp22.setLocation(38, 328);

        fSharp2 fsharp23 = new fSharp2();
        addObject(fsharp23, 90, 402);
        fsharp23.setLocation(36, 384);
        fsharp23.setLocation(37, 386);
        fsharp23.setLocation(237, 393);
        removeObject(fsharp23);
        dSharp2 dsharp22 = new dSharp2();
        addObject(dsharp22, 42, 393);
        dsharp22.setLocation(38, 386);
        Cover cover = new Cover();
        addObject(cover, 489, 296);
        cover.setLocation(112, 202);
        cover.setLocation(400, 232);
        removeObject(cover);
        Cover cover2 = new Cover();
        addObject(cover2, 21, 207);
        cover2.setLocation(10, 199);
        Cover cover3 = new Cover();
        addObject(cover3, 404, 255);
        removeObject(cover3);
        cover2.setLocation(259, 206);
        removeObject(cover2);
        Cover cover4 = new Cover();
        addObject(cover4, 18, 207);
        cover4.setLocation(15, 199);
        C c3 = new C();
        addObject(c3, 460, 399);
        cover4.setLocation(353, 207);
        removeObject(cover4);
        removeObject(c3);
        Cover cover5 = new Cover();
        addObject(cover5, 323, 248);
        removeObject(cover5);
        B b = new B();
        addObject(b, 244, 58);
        asharp.setLocation(267, 149);
        b.setLocation(56, 45);
        b.setLocation(63, 43);
        removeObject(asharp);
        aSharp asharp3 = new aSharp();
        addObject(asharp3, 49, 52);
        asharp3.setLocation(36, 55);

        ReverbButton reverbbutton = new ReverbButton();
        addObject(reverbbutton, 303, 207);
        reverbbutton.setLocation(290, 179);

        removeObject(reverbbutton);
        Reverb2 reverb2 = new Reverb2();
        addObject(reverb2, 481, 214);
        removeObject(reverb2);
        Reverb2 reverb22 = new Reverb2();
        addObject(reverb22, 486, 303);
        removeObject(reverb22);
        Reverb2 reverb23 = new Reverb2();
        addObject(reverb23, 501, 158);
        ReverbButton reverbbutton2 = new ReverbButton();
        addObject(reverbbutton2, 430, 278);
        reverbbutton2.setLocation(310, 115);
        reverb23.setLocation(522, 113);
        reverbbutton2.setLocation(330, 71);
        fsharp.setLocation(265, 234);
        removeObject(fsharp);
        F f3 = new F();
        addObject(f3, 145, 140);
        f3.setLocation(63, 133);
        fSharp fsharp3 = new fSharp();
        addObject(fsharp3, 41, 129);
        fsharp3.setLocation(36, 118);
        reverbbutton2.setLocation(320, 70);
        emptyLCD emptylcd = new emptyLCD();
        addObject(emptylcd, 533, 83);
        emptylcd.setLocation(522, 79);
        emptylcd.setLocation(527, 76);
        button1 button1 = new button1();
        addObject(button1, 472, 161);
    }
}
danpost danpost

2013/12/5

#
Every time you use the keyword 'new' in your code (see how many are in your 'prepare' method), you are creating an object. Every time you use the method 'addObject', you are adding an object into your world (again, see how many). It appears, although you create and add three of them into your world, you end up with only one Reverb2 object in your world (two of them are removed). Therefore:
Reverb2 reverb2 = (Reverb2)getWorld().getObjects(Reverb2.class).get(0);
should set the field named 'reverb2' to the object you want to change the image of, and
reverb2.setImage(/* image or image filename */);
would work to change its image.
Yedya Yedya

2013/12/5

#
OOOhh ok,that make sense now.Thanks so much for your help man,I understand it alot more now!
You need to login to post a reply.
1
2