gpt4 book ai didi

eclipse - 在 Eclipse 中使用 PyDev 调试 jython 代码时,无法为用户生成的操作命中断点

转载 作者:行者123 更新时间:2023-12-02 16:13:45 27 4
gpt4 key购买 nike

我正在使用 Eclipse 和 PyDev 插件在 Jython 中实现 GUI 应用程序。问题是我很难使用内置调试器。当我启动调试 session 时,它就会停止。当然,这应该是预料之中的,因为程序只是创建了一个 JFrame,然后就完成了。

所以我为不同事件设置的断点。按下按钮永远不会发生,因为调试 session 已经终止。

我该怎么办?我已经厌倦了使用打印来进行所有调试。

例如,当我尝试调试这个小型 Java 示例时。我没问题打我在 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);
}
}

然后我在 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

如果我尝试在调试器中运行 jython 示例,它就会终止。好的,然后我在创建 someFrame 后添加了一个断点,并在 windowClosing 方法中添加了一个断点。仍然不走运,当我关闭窗口时它没有被击中,但当我看到打印输出时我看到它被执行。

谁能告诉我我做错了什么?我确信我忘记了一些非常简单的事情。

最佳答案

在启动应用程序的主方法的第一行放置一个断点。

如果您想调试某些操作(例如按下按钮),请向按钮添加操作监听器,并在处理方法内添加断点。例如:

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
}
});

关于eclipse - 在 Eclipse 中使用 PyDev 调试 jython 代码时,无法为用户生成的操作命中断点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3889009/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com