2

I would like to be able to identify the GUI components with a class. So for example if class GUI, which extends JFrame, has a JButton component and Jpassword component, I need to be able to know that these two components are within this class, and possibly in which methods they are used.

The only idea I can think of to be able to acquire this information is parsing. Does anyone know of a library which is able to extract this kind of information from the Java source code file please?

ict1991
  • 2,060
  • 5
  • 26
  • 34
  • 1
    If you want to retrieve all the components included in a JFrame, you can use `getComponents()` recursively. For example: http://stackoverflow.com/questions/6495769/how-to-get-all-elements-inside-a-jframe – Eng.Fouad Mar 14 '12 at 09:51
  • I am not allowed to modify the code in the GUI class... as this will be given to me by some other developer... and I think it would be very messy to instantiate these classes to get this information – ict1991 Mar 14 '12 at 11:20

2 Answers2

2

Part of methods is possible by implements Reflection, maybe my question will help you

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • I will have no idea of the names of the declared field... so I dont think that I can used the results your question... i will take a look at reflection though... thanks – ict1991 Mar 14 '12 at 11:25
  • @ict1991 on this forum is a few good threads about that, be sure that JButton or JPasswordTextField is same Object as whatever another declared in Java – mKorbel Mar 14 '12 at 11:29
2

You might be able to leverage the output produced by pressing CTRL+SHIFT+F1, as described in Swing testing and debugging. Also useful in this context is a tool to detect event dispatch thread violations, recapitulated here.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045