This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
i'm trying to make 3 images become random with one of them having a string of text on it. I was curious as to if my code will make these images random and also, i'm having trouble having the image appear. I've imported them in the right way but i guess i must have formatted them wrong because i get an error messge saying that the image action variable has no value
here is the project to clarify anything:
In your applet, randomly show an image when the applet is started or restarted. Also, print a message on the applet, depending on which image is shown. Hints: the start() method would be a good place to put some sort of random flag to determine which image should be shown. It is also a good place to call a separate method to set the image and message. The paint() method should only do the actual drawing of the image and the message. Separate methods can be created to set the image and the message into variables for the paint() method to use.
sorry for not using the proper way to show code i dont know how
Mack Grill wrote: . . . sorry for not using the proper way to show code i dont know how . . .
You can click the code button, which gets you [code=java][/code] and you put your cursor inside the pair of ][. Then you can write your code there. Or you can highlight the code and push to code button. Which is what I did. Unfortunately that improves things little because you have done the only thing worse than indenting with tabs: mixing spaces and tabs.
You are using Math.random and multiplying by 2: you need to read the API documentation to see what you get, and then work out whether multiplying by 2 is any good. You are also using a very peculiar means of choosing from three possibilities. I would have thought an array would be a better way to choose; I think I have already told you that.
Also your choice is a local variable in the start() method, which you never use in the paint() method. In fact, your choice vanishes into cyber-limbo never to be seen again, long before you get anywhere near paint().