Some general hints on debugging Java (Swing) needed

G

Gertraud

I need some general hints on how to do Java maintenance - hopefully
you gurus out there can help a beginner.

I've "inherited" a non-trivial Java application (combination of
servlet and applet, swing, about 200 classes) and have to do
maintenance for it. So far I could always find out what's happening
using JSwat debugger and/or System.out.println.

But currently a problem baffles me. The application has an OK button,
which normally will behave as I want it to do: actionPerformed event
is called. In a certain situation this event will not be triggered. I
would assume, that instead some other event is triggered, which leads
to missing the "normal case" - but how can I find out, which other
event?

I have tried to put breakpoints in JSwat in all situations which
seemed marginally plausible - none of them was called. I have looked
for better tools -SpyJ and OMD sounded promising, but I couldn't get
them to work with my application. I tried to put in System.out.println
on some interesting points, but since it is not possible to instrument
all the code, I didn't hit the right ones.

What steps do you take to narrow in on problems in Swing applications?
How can I find out what events are/were triggered during my tests? Any
help is appreciated.

Thanks
 
J

jfalt

First off, it would be helpful to know what the certain condition is
where you have noticed the Ok button not behaving properly.

It seems like you are on the right track. Any click on that button is
going to go through the actionPerformed() method. The first step that
I would take would be to make sure that the event is still getting to
actionPerformed using getActionCommand() or paramString() at the
beginning of the event-handler method and dumping that to the console
or a log file.

If it doesnt seem to be reaching that point, make sure that the
listener for the button handler isnt removed at any point in the code
(using removeActionListener())
 
G

Gertraud

Thanks, jfalt for your hints.

It is not possible to describe the "certain condition" any better,
because it is fully application dependant, ie doing something in my
application I will get in a situation where the OK button does no
longer work - but only on clicking it with the mouse, ENTER still
works...

Well, I had already checked actionPerformed - in the error case it is
never hit, in all other cases it will be hit. I have put
System.out.println on the few occurrences of removeActionListener in
the code, but in the error situation none of them is met.

So I still have no idea, why actionPerformed is not called in my error
case. But fortunately I found (quite by chance) a kind of workaround
for the problem yesterday, so it is no longer as pressing as before.

Nevertheless I'm not really satisfied. Isn't there really no helpful
tool or whatever to find out what is really happening in my code??? In
the good old times of sequential code ;-), I could always find out
what's happening by debugging. Now to start debugging I have to guess
(or know the maintained code in all details) where to put my
breakpoints, otherwise debugging will never even start. For the next
problem (which is already in the queue) I will start again by trying
to guess which events could be hit, or why they aren't hit, as I would
assume by studying the code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top