在 Eclipse 上创建了一个带有按钮的框架,但它不会关闭
Created a frame with a button on eclipse but it won't close
我在 Eclipse 上创建了一个带有按钮的简单框架,但我无法关闭它。
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);
}
}
您忘记添加关闭操作:
finestra.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent we) {
finestra.dispose();
}
});
我在 Eclipse 上创建了一个带有按钮的简单框架,但我无法关闭它。
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);
}
}
您忘记添加关闭操作:
finestra.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent we) {
finestra.dispose();
}
});