views:

33

answers:

1

I'm implementing a GUI application in Jython, using Eclipse and PyDev plugin. The problem is that I have a hard time using the builtin debugger. When I start a debug session it just stops. Of course this should be expected as the program just creates a JFrame and then it's finished.

So any breakpoints I put for different events .e.g. pressing a button, will never happen as the debug session is already terminated.

What should I do ? I'm growing tired of using prints for all my debugging.

For instance, when I tried debugging this small Java example. I have no problem to hit the breakpoint I had set in the windowClosing-method

import java.awt.event.*;
import javax.swing.*;
public class Test1 {

public static void main(String s[]) {
    JFrame frame = new JFrame("JFrame Source Demo");
    // Add a window listner for close button
    frame.addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    frame.setVisible(true);
}
}

And then I tried this somewhat more or less similiar example in jython

from javax.swing import JFrame;
import java.awt.event.WindowListener as WindowListener

class Test1 (JFrame, WindowListener):
    def __init__(self):
        super(JFrame, self).__init__('Some name goes here', defaultCloseOperation = JFrame.EXIT_ON_CLOSE, size = (800, 800))
        self.addWindowListener(self)        
        self.setVisible(True)

    def windowClosing(self, windowEvent):
        print 'window closing'
        pass # want to hit this breakpoint

someFrame = Test1()
pass #breakpoint here maybe

If I tried to run the jython example in the debugger and it just terminates. Ok then I added a breakpoint after I created someFrame and a breakpoint in the windowClosing method. Still no luck, It doesn't get hit when I close the window but I see it executed as I see the printout.

Can anyone tell me what I'm doing wrong ? I'm sure I forgot something very simple.

A: 

Put a breakpoint in the first line of your main method that initiates the application.

If you want to debug certain actions like pressing a button add an action listener to a button and inside the handling method add the breakpoint. For example:

JButton button = new JButton("OK");
button.addActionListener(new ActionListener()
 {
  @Override
  public void action(ActionEvent e)
  {
   System.out.println("button OK has been pressed"; // add breakpoint here
   // call to some code that handles the event
  }
});
Boris Pavlović
Yes ok. But I still can't hit my breakpoints for other types of events (buttonclicks etc) so this doesn't really help me. Ok maybe my question is a bit wrongly formulated. The problem isn't really the application terminates prematurely. The problem is that I can't hit breakpoints for user generated events (buttonclicks, etc).
Fubar99