0

I'm working with Netbeans and I have two JFrames in same package:F1 and F2.

F1 consists of two JInternalFrames that are named in1 and in2.

F2 consists of a Jbutton named but.

Now, how can I show in1 (InternalJframe in F1), when I press but(jbutton in F2)? I mean how can I access in1 that is in F1 through F2?

4

1 回答 1

0

首先创建 F1:

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

您可以使用 F1 的参数创建 F2:

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 );
}
于 2012-01-10T17:24:42.650 回答