gpt4 book ai didi

java - 从其内部类访问类对象

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:57:13 25 4
gpt4 key购买 nike

此方法在 JFrame 对象内部,如何将该 JFrame 对象作为参数传递给其内部类中的方法?我的代码是:评论解释了我有兴趣做的事情:

public void runTime(){                ActionListener action = new ActionListener(){            public void actionPerformed(ActionEvent e){                count++;                                text.setText(new Integer(count).toString());                while (count==2012){                    //I want to pass the frame that holds this rather than null, how it is possible?                    JOptionPane.showMessageDialog(null, "HelloEnd", "End of World", JOptionPane.INFORMATION_MESSAGE, new ImageIcon("explode.jpg"));                    break;                }            }        };        tr = new Timer(1000,action);        tr.start();    } 

最佳答案

希望这个问题不是 answered before .无论如何,尝试

 JOptionPane.showMessageDialog(JFrame.this, "HelloEnd", "End of World", JOptionPane.INFORMATION_MESSAGE, new ImageIcon("explode.jpg"));

关于java - 从其内部类访问类对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4803138/

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