-1

I've created a simple Frame with a button on Eclipse but i can't close it.

package esercizi1;
import java.awt.*;


public class FinestraConBottone {
  public static void main(String[] args) {
    Frame finestra = new Frame ("Titolo");
    Button bottone = new Button ("Cliccami");

    finestra.add (bottone);
    finestra.setSize (200,200);
    finestra.setVisible (true);
  }
}
juanlumn
  • 6,155
  • 2
  • 30
  • 39

1 Answers1

0

You forgot to add the close operation:

finestra.addWindowListener(new WindowAdapter() {
    @Override
    public void windowClosing(WindowEvent we) {
        finestra.dispose();
    }
 });
CodeMatrix
  • 2,124
  • 1
  • 18
  • 30