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

2011/7/29

getClass()?

1
2
3
danpost danpost

2011/8/3

#
TextMaker is an actor There is one in the world There can be more than one------------------------------------- I am guessing that your TextMaker objects will never be at the same place, and never move. If the TextMaker objects in your world never change locations and are never located at the same place, then when you do have more than one, use the 'getObjectsAt(X, Y, TextMaker.class)' where X and Y are the coordinates of the TextMaker you want, instead of 'getObjects(TextMaker.class)'.
manster2008 manster2008

2011/8/3

#
I have one question please: You are creating a file that saves this info. somewhere correct? If so, please view the following: Ok, I think I may have a better solution to your problem. I really don't know how to save files, but if your code is right, I know how to access the string. Anyway, what I am saying is, in the SaveButton code, create a variable, a constructor and an act method such as the following:
public TextMaker myMaker;
public SaveButton(TextMaker t) {
    myMaker = t;
}
public void act() {
    if(Greenfoot.clicked(this)) {
        try {  
            // Create file   
            FileWriter fstream = new FileWriter("out.txt");  
            BufferedWriter out = new BufferedWriter(fstream);  
            out.write(myMaker.txtString);  
            //Close the output stream  
            out.close();  
        }
        catch (Exception e) {
            //Catch exception if any  
            System.err.println("Error: " + e.getMessage());  
        }
    }
}
Now, I assume you create your TextMaker objects from the world, wherever it is you do so, make your code somewhat like the following:
*this is assuming this is the world.

TextMaker t = new TextMaker();
addObject(t, x, y);
addObject(new SaveButton(t), x, y);
You need to login to post a reply.
1
2
3