I created a GUI which asks the user to select a file using JFileChooser. To be precise, the user should select a *.class file. After selecting the file, the user needs to click a button which will display all the methods in the selected class file. I have no clue or whatsoever to get the file which has been chosen using JFileChooser. I know we should use reflection API to accomplish this task but my doubt is where to insert the necessary reflection api code or should we add more code to get the things done?What type of events should be created to achieve my goal?
I also post the code which I have created. It will be helpful for me, if I get some guidance from you guys...
I have deleted the menu operations to lessen the LOC here
The greater danger for most of us is not that our aim is too high and we miss it, but that it is too low and we reach it
thanks for the quick reply. I'll try and get back here
Joined: Feb 26, 2009
Joined: Dec 29, 2008
Still I cant get my problem done.
Let me point out my problem again..
* The user needs to select a *.class file using JFileChooser (it has been done)
* After the user has selected a file, he needs to press the Display All Methods button.
* All the methods in the selected file will be displayed in the table which has been created
* I know we should use Reflection API to find the methods.
* I need to know how we can point to the selected file, before using reflection? I am clueless in this thing. (I don't know how to put it in better words)
* What should I write in the actionPerformed(ActionEvent e) for the Display All Methods button in order to get my things done.
* I am also not sure about whether I have did all other code in the right way (I mean in the lines between 236 and 252)
Note that reflection only works with *objects*, not with *classes*. So if you have some random class file you'll need to instantiate it first to use reflection. That's simple only if the class has a no-argument constructor.
If you can't make that assumption about the class you're better off using a library that works with classes, like BCEL.
This is not beginner's stuff, so I'll move it to the Intermediate forum.
I meant 'Does the program will alter(may be a wrong term) the actual byte code when we use BCEL and things like that?'. I read that we should be careful when we use Reflection API, because it deals with bytecodes..