Results 21 to 23 of 23
- 06-05-2010, 03:09 PM #21
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
No, reflection can't do that, one needs ASM to do such things but I won't recommend it to the OP; the OP has a completely incorrect paradigm in his/her head: even if it were possible (which it isn't) to 'generate' a new variable at runtime you can't refer to it because you have to type that in during compile time and therefore declare it before its first use (the compiler enforces that) therefore turning the entire thing in a catch 22. A Map<String, Image> is as close as it goes or just ordinary arrays can solve the OP's problem ...
kind regards,
Jos
- 06-05-2010, 03:13 PM #22
> As I understand you cant display multiple image unless each of them has a different variable. So I figured that if I can code the "for" loop to generate a new variable and space it, I can generate multiple pictures.
What are you going on about? Arrays?
Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)
db
- 06-05-2010, 03:14 PM #23
Senior Member
- Join Date
- May 2010
- Posts
- 436
- Rep Power
- 4
I agree that this is not clear at all which is why I've been trying to get clarification, but first and foremost for what the overall problem is rather than his code solution. My guess is that he wants to do something Java really doesn't do: create new variable names while the program is running, such as variable01, variable02, variable03, ...
And if so, then he is far better off using an array or List as I suggested, or a Map as Jos suggested.
And likely would force him into a poor program design for his problem. Now if we could only understand the details of the problem, I think we'd be easily able to help him.The only way I know to "generate" a variable is at source input time. IE when you type in the source
I think you could use reflection to generate variables at runtime, but that is way past what the OP could understand.
Similar Threads
-
Counter
By ks1615 in forum New To JavaReplies: 6Last Post: 02-20-2009, 03:02 AM -
Need helps making counter
By Lifeis2evil in forum New To JavaReplies: 3Last Post: 11-26-2008, 11:58 PM -
Frequency Counter
By justlearning in forum New To JavaReplies: 0Last Post: 05-07-2008, 10:50 PM -
[SOLVED] BST Frequency Counter
By theonly in forum Advanced JavaReplies: 7Last Post: 04-29-2008, 11:33 PM -
Help with static variable counter
By silvia in forum New To JavaReplies: 1Last Post: 07-19-2007, 07:53 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks