EscuchaVentana.java

Categorías: CategoryJava | CategoryProgramacion

   1 /**
   2  *@author Elkin Andrey Garzón Alarcón...Geek Master
   3  *@author Ingrid Lorena Guerrero Mayorga...
   4  *@author Jefferson Fabian Idarraga Idarraga Pinilla...
   5  */
   6 package pinguinogg;
   7 
   8 import java.awt.event.WindowEvent;
   9 import java.awt.event.WindowListener;
  10 import java.io.FileNotFoundException;
  11 import java.io.FileOutputStream;
  12 import java.io.IOException;
  13 import java.io.ObjectOutputStream;
  14 import java.util.TreeMap;
  15 import java.util.logging.Level;
  16 import java.util.logging.Logger;
  17 
  18 /**Esta clase hace referencia a lo que oprime el usuario desde teclado
  19  para manejar el cañon ...*/
  20 public class EscuchaVentana implements WindowListener {
  21     /**Agregar metodos para guardar puntajes*/
  22     private TreeMap<Integer, PuntajeVidas> listaPuntajes;
  23     private PuntajeVidas puntaje;
  24 
  25     public EscuchaVentana(TreeMap<Integer, PuntajeVidas> listaPuntajes, PuntajeVidas puntaje) {
  26         this.listaPuntajes = listaPuntajes;
  27         this.puntaje = puntaje;
  28     }
  29 
  30     public void windowOpened(WindowEvent e) {
  31     }
  32     /**
  33      * Cerrar la ventana y guaradn archivos
  34      * para despues motrar en la ventana puntajes.....
  35      * @param e
  36      */
  37     public void windowClosing(WindowEvent e) {
  38         System.out.println("GAME OVER");
  39 
  40         ObjectOutputStream archivo = null;
  41         listaPuntajes.put(puntaje.getPuntaje(), puntaje);
  42         try {
  43             System.err.println("Grabando el archivo");
  44             archivo = new ObjectOutputStream(new FileOutputStream("PinguinoGG.dat"));
  45             archivo.writeObject(listaPuntajes);
  46             archivo.close();
  47             System.err.print("Error-----------------");
  48             /**
  49              * verifica si hay error al grabar un archvo
  50              */
  51         } catch (FileNotFoundException ex) {
  52             System.out.println("No existe archivo");
  53             Logger.getLogger(EscuchaVentana.class.getName()).log(Level.SEVERE, null, ex);
  54         } catch (IOException ex) {
  55             Logger.getLogger(EscuchaVentana.class.getName()).log(Level.SEVERE, null, ex);
  56             
  57         } finally {
  58             try {
  59                 archivo.close();
  60             } catch (IOException ex) {
  61                 Logger.getLogger(EscuchaVentana.class.getName()).log(Level.SEVERE, null, ex);
  62             }
  63         }
  64 
  65         System.exit(0);
  66     }
  67 
  68     public void windowClosed(WindowEvent e) {
  69     }
  70 
  71     public void windowIconified(WindowEvent e) {
  72     }
  73 
  74     public void windowDeiconified(WindowEvent e) {
  75     }
  76 
  77     public void windowActivated(WindowEvent e) {
  78     }
  79 
  80     public void windowDeactivated(WindowEvent e) {
  81     }
  82 }

Java/Programas/PinguinoGg/EscuchaVentana.java (last edited 2010-10-28 11:54:12 by LorenaGuerrero)