创建了一个在Eclipse上带有按钮的框架,但是它不会关闭

时间:2019-01-09 14:43:40

标签: java eclipse button frame

我在Eclipse上用按钮创建了一个简单的Frame,但是无法关闭它。

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);
  }
}

1 个答案:

答案 0 :(得分:0)

您忘记添加关闭操作:

finestra.addWindowListener(new WindowAdapter() {
    @Override
    public void windowClosing(WindowEvent we) {
        finestra.dispose();
    }
 });