NombreDelPrograma.java

Categorías: CategoryJava | CategoryProgramacion

   1 package buddypocket;
   2 
   3 import java.awt.BorderLayout;
   4 import java.awt.Button;
   5 import java.awt.Checkbox;
   6 import java.awt.Color;
   7 import java.awt.FlowLayout;
   8 import java.awt.Frame;
   9 import java.awt.GridLayout;
  10 import java.awt.Label;
  11 import java.awt.Panel;
  12 import java.awt.TextField;
  13 import java.io.BufferedReader;
  14 import java.io.FileInputStream;
  15 import java.io.FileNotFoundException;
  16 import java.io.IOException;
  17 import java.io.InputStreamReader;
  18 import java.io.ObjectInputStream;
  19 import java.util.ArrayList;
  20 import java.util.logging.Level;
  21 import java.util.logging.Logger;
  22 import javax.swing.GroupLayout;
  23 import javax.swing.JFrame;
  24 import javax.swing.JOptionPane;
  25 
  26 
  27 /**
  28  * Esta clase main es la principal esta es en la que tiene  que  declararse todos los objetos movimientos
  29  * en esta se declarar  todo aquello que tenga  que  ver  respecto al juego
  30  * 
  31  * @author Jennifer
  32  * 
  33  */
  34 
  35 
  36 public class Main {
  37 
  38     /**
  39      * este metofo esta instanciando la  clase configuracuon y en ella  la ejecucion del mismo
  40      *  y los posibles  errores
  41      * @param args
  42      */
  43     public static void main(String[] args) {
  44         /**
  45          *
  46          */
  47         Configuracion configuration = new Configuracion();
  48         //leer  configuracionnhj
  49 
  50         try {
  51             System.err.println("Leyendo el archivo");
  52             ObjectInputStream archivo = new ObjectInputStream(new FileInputStream("configuracion.dat"));
  53             configuration = (Configuracion) archivo.readObject();
  54             archivo.close();
  55         } catch (ClassNotFoundException ex) {
  56             Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
  57         } catch (FileNotFoundException e) {
  58         } catch (IOException e) {
  59             System.err.println("escribe  error al leer el archivo de puntaje");
  60         }
  61 
  62         System.out.println("configuration.cantidadBolas = " + configuration.cantidadBolas);
  63 
  64 
  65 
  66 
  67         BufferedReader lector = new BufferedReader(new InputStreamReader(System.in));
  68         System.out.print("Digite el nombre del jugador:");
  69 
  70        
  71         String nombreJugador = JOptionPane.showInputDialog("Nombre Del Jugador");
  72 
  73 
  74 
  75         // Lee nombre del jugador
  76         
  77 
  78        
  79             nombreJugador = JOptionPane.showInputDialog("Nombre Del Jugador");
  80        
  81         Lienzo lienzo = new Lienzo();
  82 
  83         // Leer archivo de puntajes
  84 
  85         ArrayList<Puntaje> puntajes = null;
  86         try {
  87             System.err.println("Leyendo el archivo");
  88             ObjectInputStream archivo = new ObjectInputStream(new FileInputStream("buddypocket.dat"));
  89             puntajes = (ArrayList<Puntaje>) archivo.readObject();
  90             archivo.close();
  91         } catch (ClassNotFoundException ex) {
  92             Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
  93         } catch (FileNotFoundException e) {
  94             puntajes = new ArrayList<Puntaje>();
  95         } catch (IOException e) {
  96             System.err.println("escribe  error al leer el archivo de puntaje");
  97         }
  98 
  99 
 100 
 101         Frame marco = new Frame("Buddypocket");
 102         marco.setSize(1024, 800);
 103         // CREAR EL MARCO
 104         Frame marcoPuntajes = new Frame("puntajes");
 105         marcoPuntajes.setLayout(new FlowLayout());
 106         marcoPuntajes.setSize(250, 250);
 107         marcoPuntajes.add(new Label("puntajes"));
 108         //adiccionar  los puntajes como labels a marcopuntajes
 109         for (Puntaje p : puntajes) {
 110             marcoPuntajes.add(new Label(p + " "));
 111         }
 112 
 113 
 114 
 115 
 116 
 117 
 118 
 119         Fondo fondo = new Fondo(0, 0, 1024, 768);
 120 
 121 
 122 
 123         lienzo.add(fondo);
 124         Buddypocket buddypocket = new Buddypocket(0, 500, 150, 150);
 125         Buddypocket buddypocketCliente = new Buddypocket(100, 500, 150, 150);
 126 
 127         lienzo.add(buddypocketCliente);
 128         lienzo.add(buddypocket);
 129         Puntaje puntaje = new Puntaje(20, 20, 500, 50, nombreJugador);
 130 
 131         lienzo.add(puntaje);
 132 
 133         puntajes.add(puntaje);
 134 
 135 
 136 
 137 
 138 
 139 
 140         // imprimir puntajes
 141         System.out.println("------------- Puntajes --------------------");
 142         for (Puntaje p : puntajes) {
 143             System.out.println(p);
 144         }
 145 
 146 
 147         Bola[] bolas = new Bola[configuration.cantidadBolas];
 148         Thread[] hilosBolas = new Thread[bolas.length];
 149         for (int i = 0; i < bolas.length; i++) {
 150             bolas[i] = new Bola((int) (Math.random() * (1024 - 100)), (int) (Math.random() * 100), 100, 100, lienzo, buddypocket, puntaje, new Color((float) Math.random(), (float) Math.random(), (float) Math.random()));
 151             hilosBolas[i] = new Thread(bolas[i]);
 152             lienzo.add(bolas[i]);
 153         }
 154 
 155         Button botonCerrar = new Button("Iniciar");
 156         botonCerrar.addActionListener(new EscuchaBoton(marco, marcoPuntajes, bolas, hilosBolas));
 157         marcoPuntajes.add(botonCerrar);
 158 
 159 
 160 
 161 
 162 
 163 
 164         marco.addWindowListener(new Escuchaventana(puntajes));
 165         if (configuration.jugarTeclado == (true)) {
 166             marco.addKeyListener(new EscuchaTeclas(buddypocket, lienzo, bolas));
 167         }
 168 
 169 
 170         if (configuration.jugarPorMouse ==(true)) {
 171             lienzo.addMouseMotionListener(new EscuchaMoverMouse(buddypocket, lienzo));
 172         }
 173 
 174         marco.add(lienzo);
 175         Servidor servidor = new Servidor(buddypocket, lienzo);
 176         Thread hiloServidor = new Thread(servidor);
 177         hiloServidor.start();
 178 
 179 
 180         VentanaConfiguracion marcoConfiguracion = new VentanaConfiguracion(configuration);
 181         marcoConfiguracion.setSize(300, 200);
 182 
 183         /*
 184         marcoConfiguracion.setLayout(new BorderLayout());
 185         marcoConfiguracion.add(new Label("Configuracion"), BorderLayout.NORTH);
 186         Panel panelCentral = new Panel();
 187         marcoConfiguracion.add(panelCentral, BorderLayout.CENTER);
 188         panelCentral.setLayout(new GridLayout(4, 2));
 189         panelCentral.add(new Label("Direccion IP"));
 190         TextField direccionIP = new TextField(configuration.direccionIP  );
 191         panelCentral.add(direccionIP);
 192         panelCentral.add(new Label("Cantidad De Bolas"));
 193         TextField campoCantidadDeBolas = new TextField(configuration.cantidadBolas);
 194         panelCentral.add(campoCantidadDeBolas);
 195         panelCentral.add(new Label("Jugar por Mouse"));
 196         Checkbox sonido = new Checkbox("", true);
 197 
 198         panelCentral.add(sonido);
 199 
 200         panelCentral.add(new Label("Jugar por teclado"));
 201         Checkbox jugarTeclado = new Checkbox("", true);
 202         panelCentral.add(jugarTeclado);
 203         Panel panelSur = new Panel();
 204 
 205         marcoConfiguracion.add(panelSur, BorderLayout.SOUTH);
 206         panelSur.setLayout(new GridLayout(1, 2));
 207         panelSur.add(new Button("Guardar"));
 208         panelSur.add(new Button("Cancelar"));
 209 
 210         */
 211 
 212 
 213 
 214 
 215         marcoConfiguracion.setVisible(true);
 216 
 217 
 218         marco.setVisible(false);
 219 
 220         marcoPuntajes.setVisible(true);
 221     }
 222 }
 223 

Java/Programas/Buddypocket/Main.java (last edited 2010-10-28 21:58:44 by JenniferBolaños)