2012-01-04 48 views
0

我正在使用Netbeans,并且在同一个包中有两个JFrame s:F1F2如何通过其他Jframe在一个Jframe中访问JinternlFrme?

F1由名为in1in2的两个JInternalFrame组成。

F2由命名为butJbutton组成。

现在,当我按but(F2中的jbutton)时,如何显示in1(F1中的InternalJframe)? 我的意思是如何访问F1F2in1

回答

0

首先创建F1:

public class F2 extends JFrame 
{ 
    private F1 f1Frame; 
    private JButton but; 
    public F2(F1 _fromF1) 
    { 
     f1Frame = _fromF1; 
     but = new JButton("button"); 
     ... 
     ... 
     but.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent event) 
      { 
       f1Frame.makein1Visible(); 
      } 
     }); 
     .... 
     ... 
    } 
} 

在F1类实现的功能,这使得可见IN1:

public void makein1Visible() 
{ 
    in1.setVisible(true); 
} 

public static void main(String args[]) 
{ 
    F1 myF1 = new F1(); 
    F2 myF2 = new F2(myF1); 
    ... 
    ... 
} 

可以与F1的参数来创建F2

相关问题