« Return to Thread: Closing a form from another one

Closing a form from another one

by AlexanderPD :: Rate this Message:

Reply to Author | View in Thread


djohnson wrote:
> You could do it with events. Add one form as an ActionListener to the

> other form. When you want the other form to set the first one

> visible/invisible (or do anything else) fire an event to the listener

> telling it what you want it to do.

>

> HTH

>

> David Johnson

>

> On Sat, 2009-07-04 at 13:08 -0700, Jeffrey H. Coffield wrote:

>
> >

> > AlexanderPD wrote:

> >
> > > thank you for the answer :D

> > >

> > >

> > >

> > > i don't think i can do that :(

> > >

> > > my classes starts with:

> > >

> > >

> > >

> > > public class a extends javax.swing.JFrame

> > >

> > > and

> > >

> > > public class b extends javax.swing.JFrame

> > >

> > > (netbeans gui builder auto-generate that), so they both extends JFrame :(

> > >

> > >

> > > .

> > >

> > >

> > >
> > That doesn't prevent you from adding a new method with a parameter or

> > adding a method to b that will store a reference to a that can then be

> > called to set setVisble to false.

> >

> > There may be a better way to do this, and if someone else has an idea,

> > I'd also like to know.

> >

> > Jeff Coffield

> >

> > Jeff

> >
>




i tryed that.. without any success :(

i'll post the first class:




Code:
package progettoos;



public class a extends javax.swing.JFrame {



    public a() {

        initComponents();

    }

    @SuppressWarnings("unchecked")

    // <editor-fold defaultstate="collapsed" desc="Generated Code">

    private void initComponents() {



        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);



        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

        getContentPane().setLayout(layout);

        layout.setHorizontalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGap(0, 400, Short.MAX_VALUE)

        );

        layout.setVerticalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGap(0, 300, Short.MAX_VALUE)

        );



        pack();

    }// </editor-fold>



    public static void main(String args[]) {

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {

                new a().setVisible(true);

            }

        });

    }

    // Variables declaration - do not modify

    // End of variables declaration

}







it's a totally empty interface, and if i try to use the "a.setvisible(false)" or "a.dispose" i get the "non-static method cannot be referenced from a static context", ever if i type it just after the initComponents();

it works if i use this.setVisible(false) or this.dispose(), but not if i write it in a static method..

so, how i can close it from another jframe or another class?




 « Return to Thread: Closing a form from another one