This week's book giveaway is in the NodeJS forum. We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line! See this thread for details.
I am trying to get the value of the Gui field JFrame frame at runtime using reflection.I have 3 classes one for the gui,one for reflection, then the main to call doFrame()
So first i run the frame then after the values have been intitialized. I want to use my AddReflection class to print out the Gui frame field. I believe my problem is that im creating a new Gui so the frame field
wont reference the frame that has been intialized. Sorry if my post is hard to understand
So at line 13 you create a Gui object. It has a JFrame variable, which is initialized to null.
Then at line 16 line 22 you use reflection to get the value of that variable, which is null. Your reflection code looks okay to me although it might be wrong.
I think perhaps you are surprised by that.
Your commented-out code from line 17 to 20 doesn't look right to me, though.
However you never mentioned anything about the problem you're having, so all that is based on guesswork. It would help if you described the problem. Compiler errors? Runtime errors? Unexpected output? Have a look at this link: TellTheDetails for more info on how to describe a problem.
Kyle Keyser wrote:I believe my problem is that im creating a new Gui so the frame field wont reference the frame that has been intialized.
You are creating a Gui object, but not calling the method to initialize the frame field. You need to call your doFrame() method.
posted 2 weeks ago
Thanks for the quick responses.Hi I did create a Gui object in my main class that calls the doFrame() just didn't list that code. What I want to happen is I want to create the gui which I do Then while the gui is created/still running the frame field would be initialized which it is and has a title of test. Then I want to run my addReflection class and take the gui that is runnings initialized Jframe field which has a title value test. I expect it to be null because I created a new instance of it which would be set to null but what I want is for it to be the Jframe values for the running gui. I don't think its possible using just reflection though. Maybe I need to use injection for this
Well, there isn't an object there until you assign a value to the variable. Which is what the doFrame() method does. So until you call the doFrame() method of your Gui object, there's no object to be seen. That's what Ron said, and he showed you how to do it.
Anyway seeing the JFrame object isn't going to be exciting. You're just going to see a short meaningless string of mostly numbers.
If you're trying to learn how to use reflection, then this idea is okay. If you were hoping to expand it into something useful, well, I don't know what that might be.
posted 2 weeks ago
This is just a simplified test. I know their currently isnt a value but when I have the client running cause I do call the doFrame() method. Just say you have a Client running on your computer it has a Jframe/panels/applet and you want to get those values so you can place it in your own Jframe. I really just don't think I can do this with reflection because im trying to do it while it is running. I don't want to receive the byte code that it was compiled to which I think is what reflection does. I think I need injection javassit/asm/ or something. Sorry if none of this made sense lol
I do have to agree that it doesn't make much sense. In your code you already have a reference to the JFrame object. Once you have that you don't really need reflection to examine the object, given that you already know it's a JFrame. You can call any of its methods. (And no, reflection has nothing at all to do with receiving byte code.) And it doesn't matter at all that the JFrame is "running" -- in fact if it isn't running then there isn't much point in accessing it.
On the other hand if the JFrame is in a different JVM than the code you're trying to write, then reflection isn't going to help. To use reflection you still need to get a reference to the object, which you can't because it's in a different JVM.
If your underlying wish is to have your JVM communicate with this other JVM which is already running, then there are ways to do that. However direct access from JVM A to objects in JVM B isn't one of those ways. I think it might be a good idea if you backed up and described the reason why you thought that might be a good idea.
If you two don't stop this rough-housing somebody is going to end up crying. Sit down and read this tiny ad:
global solutions you can do at home or in your backyard