Hello , Im having a problem in disposing my jframes..
this is the scenario of my problem

my mainFrame have button that will navigate my 2ndFrame and my 2ndFrame have a button that will navigate my 3rdFrame..the problem is how can the button of my 3rdFrame dispose my mainFrame? hmm? i want the 3rd frame to stay ..System.exit(0) close all frames;

here's my sample codes..

for mainFrame i use this code so i can call it in my 3rdFrame

     public void actionPerformed(ActionEvent e){
 
     this.dispose() ; }

for my 3rdframe

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {  
 
    mainFrame f= new mainFrame();  
    f.actionPerformed(evt);
}

it's not working

i'll appreciate all your suggestions and help!
thank you in advance : )