2012-01-04 52 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

相關問題