Ciao; ho fatto questo piccolo esempio; spero ti possa aiutare.
CiaoCodice 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.setSize( 200,200 );
this.show();
}
private void init(){
bottone.addActionListener( new myActionListener( this ) );
pannello.add( bottone );
this.getContentPane().add( pannello );
}
public static void main(String[] args) {
new Prova();
}
}
class myActionListener implements java.awt.event.ActionListener{
private Prova p1;
public myActionListener( Prova p ){
p1 = p;
}
public void actionPerformed( ActionEvent e ){
this.p1.dispose();
//Se vuoi far terminare l'applicazione togli il commento alla
//linea seguente:
//System.exit( 1 );
}
}
![]()

Rispondi quotando