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

2016/10/28

Displaying an array with random numbers on an Image

arshbhatti8 arshbhatti8

2016/10/28

#
I am trying to display an array that has random numbers on an image. I intend to sort the numbers displayed and make some kind of an animation to explain how it is being done. I have been successful at generating those numbers and using the random class but I am stuck at displaying those numbers on the screen. I do not want to do a 'System.out.println'. The only way of displaying the array onto the image I see is to parse it into a string and use GreenfootImage.drawString() to draw it onto the image. The problem with this is that I cannot do any operations (sorting) on that string later.
Super_Hippo Super_Hippo

2016/10/28

#
You could have a class and the image of it is the number you want to display. So in the end, every number is an own actor and you can change the displayed number/string later if needed.
arshbhatti8 arshbhatti8

2016/10/29

#
So, what you are trying to say is that for every random number that i might generate, it will have its own class?
danpost danpost

2016/10/29

#
arshbhatti8 wrote...
So, what you are trying to say is that for every random number that i might generate, it will have its own class?
No -- just an separate object from the same class. My Value Display Tutorial shows how to make a Counter class, which your new class would be quite similar to; just that instead of an 'adjustValue' method, you may want to use a 'setValue' method.
You need to login to post a reply.