我在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);
}
}
答案 0 :(得分:0)
您忘记添加关闭操作:
finestra.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent we) {
finestra.dispose();
}
});