在Eclipse调试会话期间出现Java GUI更改

时间:2017-02-20 07:22:02

标签: java eclipse user-interface debugging

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.SwingUtilities;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Debug_Q1 {
    protected static JButton[] t = new JButton[5];

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                showButtons();
            }
        });
    }

    public static void showButtons() {
        int     i, y = 30, wid = 50, ht = 50;

        if (!javax.swing.SwingUtilities.isEventDispatchThread())  {
            System.err.println("NOT on the 'Event Dispatching Thread'");
            return;                                 // abort
        }

        JFrame frame = new JFrame("Debug Buttons");
        frame.setBounds(350,55, 330,160);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);

        JPanel bBoard = new JPanel();               
        bBoard.setLayout(null);
        JButton setCaps = new JButton("Set Captions");
        setCaps.setBounds(100, 90, 120, 30);
        setCaps.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                showSetup();
            }
        });

        bBoard.add(setCaps);
        bBoard.setVisible(true);

        for (i = 0;  i < 5;  i++) {
            t[i] = new JButton();                   // new JBtn
            t[i].setBounds(i*60+10, y, wid, ht);    // * set loc & size
            bBoard.add(t[i]);                       // * add to panel
        }
        frame.add(bBoard);                          // add panel to frame
    }

    public static void showSetup() {
        for (int i = 0;  i < 5;  i++) {
            if (i%2 == 1) t[i].setText("");
            else          t[i].setText(Integer.toString(i));
        }
    }
}

我已编辑了原始问题以显示完整的代码示例 (以上)。如果我在showSetup()循环和步骤中设置断点 通过循环,当setText()时,标题不会更新 执行。我怎么能强迫这种情况发生呢?

我正在使用简单的GUI开发Java Swing程序:JFrame, JPanel和几个JButtons。在执行期间,我更改了文本 按钮。但是在Eclipse Neon Debug Perspective中,这些文本 在程序停止之前不会出现更改,等待下一个 用户输入。当我单步执行时,如何显示更改 码?

0 个答案:

没有答案
相关问题