2013-03-07 28 views
0

你好朋友我有一个扩展JFrame并具有JInternalFrames的swing应用程序。我需要从JInternalFrame中的ActionEvent刷新MainFrame。 我的大型机(伪)刷新来自Jinternal Frame的JFrame

public class MainFrame extends JFrame{ 
    ................. 

    } 
public void Refresh(){ 
    invalidate(); 
    validate(); 
    } 

我的JInternalFrame(Pseud0)

public class EndOfTerm extends JInternalFrame implements ActionListener{ 

public void actionPerformed(ActionEvent ae){ 

......... 
new MainFrame().Refresh(); 

} 

} 

我的动作事件,一个没有组件,第二个与似乎重叠组件后,得到两帧。请帮忙。 #初学者#

+1

'new MainFrame()。Refresh();'通过这个你正在创建新的主机实例,而不是你应该参考启动内部框架的同一个实例。有关SSCCE的更多帮助信息。 – 2013-03-07 13:29:50

+0

请不要拿......因为我不知道任何真正的原因(代码不是SSCCE形式),只是我的好奇心,你能描述一下你的理由, – mKorbel 2013-03-07 13:31:19

+0

我的课程非常庞大,因为它是一个大应用。 – ErrorNotFoundException 2013-03-07 13:33:26

回答

1

你必须将你的MainFrame保存在你的InternalFrame中。

public class EndOfTerm extends JInternalFrame implements ActionListener{ 

    private MainFram mainFrame; 

    public EndOfTerm(MainFrame mainFrame) { 
     this.mainFrame = mainFrame; 
    } 

    public void actionPerformed(ActionEvent ae){ 

     ......... 
     mainFrame.Refresh(); 

    } 

} 

当你创建你的InternalFrame时,你必须通过你的MainFrame。

new InternalFrame(this); 
+0

空指针异常 – ErrorNotFoundException 2013-03-07 13:43:37

+0

您从哪里得到NullPoinerException? – mklnwt 2013-03-07 13:45:38

+0

它在主机架上出现 – ErrorNotFoundException 2013-03-07 13:54:24

0

我想你也可以在你的JInternalFrame中调用getParent(this)来获得对封闭JFrame的引用。