EscuchaVentana.java
Categorías: CategoryJava | CategoryProgramacion |
1
2 package savetheearthsk;
3
4 import java.awt.Frame;
5 import java.awt.event.WindowEvent;
6 import java.awt.event.WindowListener;
7 import java.io.FileNotFoundException;
8 import java.io.FileOutputStream;
9 import java.io.IOException;
10 import java.io.ObjectOutputStream;
11 import java.util.Map;
12 import java.util.logging.Level;
13 import java.util.logging.Logger;
14
15 /**
16 * @author lina Maria Angelica Bermudez Leon
17 * @author Mario Nicolas Arcila Escobar
18 */
19
20 /**
21 * es la clase que permite reconocer las acciones de las ventanas
22 */
23 public class EscuchaVentana implements WindowListener {
24
25 Frame frame = new Frame("puntajes");
26 private Map<Integer, Puntaje> puntajes;
27 private Puntaje puntaje;
28
29 /** esta es la costructora
30 * @param puntajes son los puntajes guardados en el mapa
31 * @param puntaje es el puntaje actual del jugador
32 */
33 public EscuchaVentana(Map<Integer, Puntaje> puntajes, Puntaje puntaje) {
34
35
36 this.puntajes = puntajes;
37 this.puntaje = puntaje;
38
39 }
40 /**
41 * es el metodo para cerrar la ventana
42 */
43 public void windowClosing(WindowEvent f) {
44 //imprimir puntaje
45 //
46 System.out.println("Puntajes\n");
47
48 System.err.println("getSet = " + puntajes.keySet());
49
50 System.out.println("Puntajes");
51 for (Puntaje p : puntajes.values()) {
52 System.out.println(p);
53 }
54
55 // frame.add(new Label());
56
57 //System.out.println(p);
58 puntajes.put(puntaje.getCantidad(), puntaje);
59 puntajes.keySet();
60
61
62 try {
63 ObjectOutputStream archivo = new ObjectOutputStream(new FileOutputStream("juego.dat"));
64 archivo.writeObject(puntajes);
65 archivo.close();
66 } catch (FileNotFoundException e) {
67 System.err.println("no existe el archivo");
68 Logger.getLogger(EscuchaVentana.class.getName()).log(Level.SEVERE, null, e);
69 } catch (IOException ex) {
70 Logger.getLogger(EscuchaVentana.class.getName()).log(Level.SEVERE, null, ex);
71 }
72
73 System.exit(0);
74
75 }
76
77 public void windowOpened(WindowEvent e) {
78 }
79
80 public void windowClosed(WindowEvent e) {
81 }
82
83 public void windowIconified(WindowEvent e) {
84 }
85
86 public void windowDeiconified(WindowEvent e) {
87 }
88
89 public void windowActivated(WindowEvent e) {
90 }
91
92 public void windowDeactivated(WindowEvent e) {
93 }
94 }
