Ciao; ho fatto questo piccolo esempio; spero ti possa aiutare.

Codice PHP:
import javax.swing.JWindow;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.event.*;

public class 
Prova extends JWindow {
  
  
JButton bottone = new JButton("Premi");
  
JPanel pannello = new JPanel();
  
  public 
Prova(){
    
    
this.init();
    
this.setSize200,200 );
    
this.show();
  }
  private 
void init(){
    
    
bottone.addActionListener( new myActionListenerthis )  );
    
pannello.addbottone );
    
this.getContentPane().addpannello );
  }
  public static 
void main(String[] args) {
    
    new 
Prova();
  }
}
class 
myActionListener implements java.awt.event.ActionListener{
  
  private 
Prova p1;
  public 
myActionListenerProva p ){
    
    
p1 p;
  }
  
  public 
void actionPerformedActionEvent e ){
    
    
this.p1.dispose();
    
//Se vuoi far terminare l'applicazione togli il commento alla 
    //linea seguente:
    //System.exit( 1 );
  
}

Ciao