此方法在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(); }
答案 0 :(得分:4)
希望这个问题不是answered before。无论如何,试试
JOptionPane.showMessageDialog(JFrame.this, "HelloEnd", "End of World", JOptionPane.INFORMATION_MESSAGE, new ImageIcon("explode.jpg"));
答案 1 :(得分:1)
您可以使用OuterClassName.this
。
答案 2 :(得分:0)
AFAIK,如果您的方法不是静态的,则可以使用this
和super
个关键字。这是一些tutorial。例如:
JOptionPane.showMessageDialog(this, "HelloEnd", "End of World", JOptionPane.INFORMATION_MESSAGE, new ImageIcon("explode.jpg"));