El siguiente paso consiste en hacer que la ventana se comporte como es debido : terminando el programa
cuando es cerrada. La forma de hacerlo es la tradicional mediante un gestor del evento WindowClosing, con el
correspondiente System.exit(0) en su interior
1 package version02;
2
10
11
12 import java.awt.event.WindowAdapter;
13 import java.awt.event.WindowEvent;
14 import javax.swing.JFrame;
15
16 public class Invaders {
17 public static final int WIDTH = 800;
18 public static final int HEIGHT = 600;
19
20 public Invaders() {
21 JFrame ventana = new JFrame("Invaders");
22 ventana.setBounds(0,0,WIDTH,HEIGHT);
23 ventana.setVisible(true);
24 ventana.addWindowListener(
new WindowAdapter() {
25 public void windowClosing(WindowEvent e) {
26 System.exit(
0);
27 }
28 });
29
30 }
31
32 public static void main(String[] args) {
33 Invaders inv = new Invaders();
34 }
35 }
36
(c) 2004 Planetalia S.L. Todos los derechos reservados. Prohibida su reproducción