miércoles, 23 de noviembre de 2011

Documentación técnica y auto-generación de código

Documentación técnica y auto-generación de código de ogro y príncipe

Para realizar la auto-generación de código del juego del ogro y príncipe, utilizare Umbrello.

En la terminal nos posicionamos en la carpeta del juego y escribimos lo siguiente umbrello juego.

Se desplegará el diagrama de clases del proyecto juego del ogro y príncipe.
Para la auto-generación de código, daremos click en la opción Code y damos click a Code Generation Wizard y nos aparecerá una ventana como esta:


Ahora le damos click al botón Next y nos aparecerá otra ventana en la que nos aparece la dirección en que se guardara la auto-generación del código y además aparece en que lenguaje deseamos que se auto-genere el código, en este caso pondre la opción que el código se realice en el lenguaje Java. Damos click al botón Next.
Nos aparecerá otra ventana en la que daremos click a Generate. Y automáticamente el código del ogro y el príncipe se a generado en el lenguaje Java a partir del diagrama de clases creado en Umbrello.

Código auto-generado
/**
* Class Personaje
*/
public class Personaje {

//
// Fields
//

private String nombre;

//
// Constructors
//
public Personaje () { };

//
// Methods
//


//
// Accessor methods
//

/**
* Set the value of nombre
* @param newVar the new value of nombre
*/
private void setNombre ( String newVar ) {
nombre = newVar;
}

/**
* Get the value of nombre
* @return the value of nombre
*/
private String getNombre ( ) {
return nombre;
}

//
// Other methods
//

}
/**
* Class Princesa
*/
public class Princesa extends Personaje implements Capturable {

//
// Fields
//

private String status = "libre";

//
// Constructors
//
public Princesa () { };

//
// Methods
//


//
// Accessor methods
//

/**
* Set the value of status
* @param newVar the new value of status
*/
private void setStatus ( String newVar ) {
status = newVar;
}

/**
* Get the value of status
* @return the value of status
*/
private String getStatus ( ) {
return status;
}

//
// Other methods
//

/**
*/
public void capturar( )
{
}


/**
*/
public void liberar( )
{
}


}
import java.util.*;


/**
* Class Principe
*/
public class Principe extends PersonajeAtacable implements Curable {

//
// Fields
//


//
// Constructors
//
public Principe () { };

//
// Methods
//


//
// Accessor methods
//

//
// Other methods
//

/**
* @return Mago
*/
public Mago invocarMago( )
{
}


/**
* @param o
*/
public void atacar( Ogro o )
{
}


/**
* @param c
*/
public void rescatar( Capturable c )
{
}


/**
* @return int
*/
public int curar( )
{
}


}
/**
* Class PersonajeAtacable
*/
public class PersonajeAtacable extends Personaje implements Atacable {

//
// Fields
//

static private int DEFAULT_VIDA = 100;
private int vida;

//
// Constructors
//
public PersonajeAtacable () { };

//
// Methods
//


//
// Accessor methods
//

/**
* Get the value of DEFAULT_VIDA
* @return the value of DEFAULT_VIDA
*/
private int getDEFAULT_VIDA ( ) {
return DEFAULT_VIDA;
}

/**
* Set the value of vida
* @param newVar the new value of vida
*/
private void setVida ( int newVar ) {
vida = newVar;
}

/**
* Get the value of vida
* @return the value of vida
*/
private int getVida ( ) {
return vida;
}

//
// Other methods
//

/**
* @param cuanta
*/
public void restarVida( int cuanta )
{
}


/**
* @param a
*/
public void atacar( Atacable a )
{
}


/**
* @param intensidad
*/
public void recibirAtaque( int intensidad )
{
}


}
import java.util.*;


/**
* Class Ogro
*/
public class Ogro extends PersonajeAtacable implements Capturable, Congelable {

//
// Fields
//

private boolean congelado = false;

//
// Constructors
//
public Ogro () { };

//
// Methods
//


//
// Accessor methods
//

/**
* Set the value of congelado
* @param newVar the new value of congelado
*/
private void setCongelado ( boolean newVar ) {
congelado = newVar;
}

/**
* Get the value of congelado
* @return the value of congelado
*/
private boolean getCongelado ( ) {
return congelado;
}

//
// Other methods
//

/**
* @param c
*/
public void capturar( Capturable c )
{
}


/**
*/
public void capturar( )
{
}


/**
*/
public void liberar( )
{
}


/**
*/
public void congelar( )
{
}


}
import java.util.*;


/**
* Class Mago
*/
public class Mago extends Personaje {

//
// Fields
//


//
// Constructors
//
public Mago () { };

//
// Methods
//


//
// Accessor methods
//

//
// Other methods
//

/**
* @param c
*/
public void lanzarHechizo( Congelable c )
{
}


/**
* @param c
*/
public void curar( Curable c )
{
}


}
/**
* Interface Curable
*/
public interface Curable {

//
// Fields
//


//
// Methods
//


//
// Accessor methods
//

//
// Other methods
//

/**
* @return int
*/
public int curar( );


}
/**
* Interface Congelable
*/
public interface Congelable {

//
// Fields
//


//
// Methods
//


//
// Accessor methods
//

//
// Other methods
//

/**
*/
public void congelar( );


}
/**
* Interface Capturable
*/
public interface Capturable {

//
// Fields
//


//
// Methods
//


//
// Accessor methods
//

//
// Other methods
//

/**
*/
public void capturar( );


/**
*/
public void liberar( );


}
/**
* Interface Atacable
*/
public interface Atacable {

//
// Fields
//


//
// Methods
//


//
// Accessor methods
//

//
// Other methods
//

/**
* @param a
*/
public void atacar( Atacable a );


/**
* @param intensidad
*/
public void recibirAtaque( int intensidad );


}
Como vimos en el código anterior se encuentran algunos comentarios inicializados con /** y terminados con */, esto es parte de la documentación técnica.
Dentro de la documentación en un proyecto podrán ir diferentes identificadores como:
@author - Autor del código fuente
@exception - Excpeciones del código
@param - Parámetros que se reciben en los métodos
@return - El valor que se regresa

Cualquier identificador comienza con /** y termina con */. Además cada línea escrita dentro de esos símboloes tendrán un * al comenzar.

Por ejemplo:
/**
*Esto es un ejemplo
*@return ejemplo
*/

Ahora para realizar la documentación técnica del juego el ogro y el príncipe, utilizare JavaDoc.
En la terminal, dentro de la carpeta del código fuente que se auto-generó, escribimos: javadoc *.java

Después de esto, la documentación del código fuente se generó. Se generaron varios archivos, entre ellos un archivo llamado index.html. Abrimos este archivo y se mostrará toda la documentación del juego del ogro y el príncipe.

Algunas imagenes de la documentación



En la documentación se muestran el constructor, los métodos, parámetros, atributos, etc del código fuente del ogro y el príncipe.

Referencias



Saludos.

martes, 22 de noviembre de 2011

Sistemas Distribuidos

El proyecto que yo realize es un sistema de un Videoclub que puede ser distribuido como un sistema cliente-servidor.

En cuanto a compatibilidad, el sistema esta creado en el lenguaje JAVA. Por la razón anterior el sistema, puede distribuirse en cualquier plataforma. Pero además, utiliza una base de datos, creada en MySQL, el cual tiene la ventaja de ser un software libre.

Puede ser utilizado por cualquier persona, lo cual es poco confiable, ya que no cuenta con contraseña de administrador, ni de usuarios.

En cuanto a tolerancia a fallos, el sistema puede producir fallos por diferentes razones, principalmente por la base de datos en MySQL, ya que podría haber concurrencia al acceder a la base de datos.

Referencias

viernes, 4 de noviembre de 2011

Eventos y excepciones

Algunos de los eventos y excpeciones en mi proyecto son los siguientes:

Clase Película y Cliente (conexión con la base de datos)
try{
Class.forName("com.mysql.jdbc.Driver");

conexion = DriverManager.getConnection("jdbc:mysql://localhost/videoclub", "root", "gjosue19");
System.out.println("Conexion realizada");
}
catch(ClassNotFoundException e){
System.out.println(e);
}
catch(SQLException e){
System.out.println(e);
}

Clase Cliente (método agregar)
 try{
st = conexion.createStatement();

st.executeUpdate("INSERT INTO cliente(nombre, telefono, colonia, calle, numero, cp) VALUES ('"+name+"', '"+tel+"', '"+col+"', '"+ca+"', '"+num+"', '"+codp+"')");

System.out.println("Se insertaron los datos");

JOptionPane.showMessageDialog(null, "Se han insertado los datos", "Cliente agregado", JOptionPane.WARNING_MESSAGE);

}catch(Exception e){
System.out.println("No se insertaron los datos");
JOptionPane.showMessageDialog(null, "No se han insertado los datos", "Cliente agregado", JOptionPane.WARNING_MESSAGE);
}

Clase Cliente (eventos de los botones)
public void actionPerformed(ActionEvent e){

if(bMenu == e.getSource()){
Videoclub vid = new Videoclub();
vid.crearVentanaV();
cliente.dispose();
}

if(bAgr == e.getSource()){
registrar();
}

if(bCan == e.getSource()){
System.exit(0);
}

if(limpiar == e.getSource()){
textNom.setText("");
textTel.setText("");
textCol.setText("");
textC.setText("");
textNum.setText("");
textCP.setText("");
}

}
Clase Película (eventos de los botones)
 public void actionPerformed(ActionEvent e){

if(botM == e.getSource()){
Videoclub vid = new Videoclub();
vid.crearVentanaV();
pelicula.dispose();
}

if(botAgP == e.getSource()){
agregar();
}

if(botCP == e.getSource()){
System.exit(0);
}
if(botLim == e.getSource()){
textTit.setText("");
textGen.setText("");
textCl.setText("");
textCV.setText("");
textCR.setText("");
textCantV.setText("");
textCantR.setText("");
}

if(botE == e.getSource()){
eliminar();
}

if(botC == e.getSource()){
System.exit(0);
}

if(botL == e.getSource()){
textNumPel.setText("");
}

if(botCPel == e.getSource()){
consultar();
}

}

Clase Película (método agregar)
  try{

st = conexion.createStatement();

st.executeUpdate("INSERT INTO pelicula(titulo, genero, clasif, costoVta, costoRta, cantVta, cantRta) VALUES ('"+tit+"', '"+gen+"', '"+cl+"', '"+CV+"', '"+CR+"', '"+cantV+"', '"+cantR+"')");

System.out.println("Se insertaron los datos");
JOptionPane.showMessageDialog(null, "Se han insertado los datos", "Pelicula agregada", JOptionPane.WARNING_MESSAGE);

}catch(Exception e){
System.out.println("Aun No se insertaron los datos");
JOptionPane.showMessageDialog(null, "No se han insertado los datos", "Pelicula agregada", JOptionPane.WARNING_MESSAGE);

}
Clase Película (método eliminar)
 try{

st = conexion.createStatement();

st.executeUpdate("DELETE FROM pelicula WHERE id = '"+numPel+"'");

System.out.println("Se borraron los datos");
JOptionPane.showMessageDialog(null, "Se han eliminado los datos", "Pelicula eliminada", JOptionPane.WARNING_MESSAGE);

}catch(Exception e){
System.out.println("Aun no se borraron los datos");
JOptionPane.showMessageDialog(null, "No se han eliminado los datos", "Pelicula agregada", JOptionPane.WARNING_MESSAGE);

}
Clase Película (método consultar)
 try{
st = conexion.createStatement();
rs = st.executeQuery("SELECT * FROM pelicula where id = '"+numPel+"'");

while(rs.next()){
labTitulo.setText(""+rs.getObject(2));
labGenero.setText(""+rs.getObject(3));
labClas.setText(""+rs.getObject(4));
labCVta.setText(""+rs.getObject(5));
labCRta.setText(""+rs.getObject(6));

System.out.println("Consultando datos");
}

}catch(Exception e){
System.out.println("Aun no se han podido consultar los datos");
}
Clase TicketVenta (eventos de botones)
    public void actionPerformed(ActionEvent e){
if(botM == e.getSource()){
Videoclub vid = new Videoclub();
vid.crearVentanaV();
venta.dispose();
}

if(botAgP == e.getSource()){
consultar();
}

if(botAc == e.getSource()){
agregar();
}

if(botC == e.getSource()){
System.exit(0);
}
}
Clase TicketVenta (método consultar)
 try{
st = conexion.createStatement();
rs = st.executeQuery("SELECT * FROM pelicula where id = '"+num_pel+"'");

while(rs.next()){
titulo.setText(""+rs.getObject(2));
genero.setText(""+rs.getObject(3));
clasificacion.setText(""+rs.getObject(4));
costoVta.setText(""+rs.getObject(5));

System.out.println("Consultando datos");
String dato = String.valueOf(rs.getObject(5));
int x = Integer.parseInt(dato);
tot = tot + x;
total.setText(""+tot);

}

}catch(Exception e){
System.out.println("Aun no se han podido consultar los datos");
}
Clase TicketVenta (método agregar)
try{
st = conexion.createStatement();

st.executeUpdate("INSERT INTO ventas(total) VALUES ('"+tot+"')");

System.out.println("Se insertaron los datos");

JOptionPane.showMessageDialog(null, "Venta generada", "Ventas", JOptionPane.WARNING_MESSAGE);
}catch(Exception e){
System.out.println("No se insertaron los datos");

}

Referencias

Saludos.

Interfaz gráfica

Interfaz gráfica de mi proyecto.

Para realizar la interfaz gráfica utilice los Layouts GridLayout y GridBagLayout, este último fue el que mas utilice para acomodar los componentes como los JTextField, JButton, JLabel en los diferentes paneles que coloque en las ventanas.

Ventana prinicipal de menú


Ventana de Clientes


Ventana de Películas


Ventana de Ventas


Ventana de Rentas


Referencias

Saludos.

lunes, 24 de octubre de 2011

Auto-generación de código

Para realizar la auto-generación de código de mi proyecto, hice el diagrama de clases utilizando la herramienta Umbrello.

El código auto-generado es el siguiente:

Clase Empleado
/**
* Class Empleado
*/
public class Empleado {

//
// Fields
//

private int no_empleado;
private String nom_empleado;
private int contraseña;

//
// Constructors
//
public Empleado () { };

//
// Methods
//


//
// Accessor methods
//

/**
* Set the value of no_empleado
* @param newVar the new value of no_empleado
*/
private void setNo_empleado ( int newVar ) {
no_empleado = newVar;
}

/**
* Get the value of no_empleado
* @return the value of no_empleado
*/
private int getNo_empleado ( ) {
return no_empleado;
}

/**
* Set the value of nom_empleado
* @param newVar the new value of nom_empleado
*/
private void setNom_empleado ( String newVar ) {
nom_empleado = newVar;
}

/**
* Get the value of nom_empleado
* @return the value of nom_empleado
*/
private String getNom_empleado ( ) {
return nom_empleado;
}

/**
* Set the value of contraseña
* @param newVar the new value of contraseña
*/
private void setContraseña ( int newVar ) {
contraseña = newVar;
}

/**
* Get the value of contraseña
* @return the value of contraseña
*/
private int getContraseña ( ) {
return contraseña;
}

//
// Other methods
//

/**
*/
public void entrar( )
{
}


/**
*/
public void consultar( )
{
}


}
Clase Cliente
/**
* Class Cliente
*/
public class Cliente {

//
// Fields
//

private int no_cliente;
private String nom_cliente;
private String colonia;
private String calle;
private int no_dir;
private int cp_dir;
private int tel_cliente;

//
// Constructors
//
public Cliente () { };

//
// Methods
//


//
// Accessor methods
//

/**
* Set the value of no_cliente
* @param newVar the new value of no_cliente
*/
private void setNo_cliente ( int newVar ) {
no_cliente = newVar;
}

/**
* Get the value of no_cliente
* @return the value of no_cliente
*/
private int getNo_cliente ( ) {
return no_cliente;
}

/**
* Set the value of nom_cliente
* @param newVar the new value of nom_cliente
*/
private void setNom_cliente ( String newVar ) {
nom_cliente = newVar;
}

/**
* Get the value of nom_cliente
* @return the value of nom_cliente
*/
private String getNom_cliente ( ) {
return nom_cliente;
}

/**
* Set the value of colonia
* @param newVar the new value of colonia
*/
private void setColonia ( String newVar ) {
colonia = newVar;
}

/**
* Get the value of colonia
* @return the value of colonia
*/
private String getColonia ( ) {
return colonia;
}

/**
* Set the value of calle
* @param newVar the new value of calle
*/
private void setCalle ( String newVar ) {
calle = newVar;
}

/**
* Get the value of calle
* @return the value of calle
*/
private String getCalle ( ) {
return calle;
}

/**
* Set the value of no_dir
* @param newVar the new value of no_dir
*/
private void setNo_dir ( int newVar ) {
no_dir = newVar;
}

/**
* Get the value of no_dir
* @return the value of no_dir
*/
private int getNo_dir ( ) {
return no_dir;
}

/**
* Set the value of cp_dir
* @param newVar the new value of cp_dir
*/
private void setCp_dir ( int newVar ) {
cp_dir = newVar;
}

/**
* Get the value of cp_dir
* @return the value of cp_dir
*/
private int getCp_dir ( ) {
return cp_dir;
}

/**
* Set the value of tel_cliente
* @param newVar the new value of tel_cliente
*/
private void setTel_cliente ( int newVar ) {
tel_cliente = newVar;
}

/**
* Get the value of tel_cliente
* @return the value of tel_cliente
*/
private int getTel_cliente ( ) {
return tel_cliente;
}

//
// Other methods
//

/**
*/
public void registrar( )
{
}


}
Clase Película
/**
* Class Pelicula
*/
public class Pelicula {

//
// Fields
//

private int no_pel;
private String titulo;
private String material;
private String situacion;
private String genero;
private String clasificacion;
private double costoVta;
private double costoRta;
private int cantpel_vta;
private int cantpel_rta;

//
// Constructors
//
public Pelicula () { };

//
// Methods
//


//
// Accessor methods
//

/**
* Set the value of no_pel
* @param newVar the new value of no_pel
*/
private void setNo_pel ( int newVar ) {
no_pel = newVar;
}

/**
* Get the value of no_pel
* @return the value of no_pel
*/
private int getNo_pel ( ) {
return no_pel;
}

/**
* Set the value of titulo
* @param newVar the new value of titulo
*/
private void setTitulo ( String newVar ) {
titulo = newVar;
}

/**
* Get the value of titulo
* @return the value of titulo
*/
private String getTitulo ( ) {
return titulo;
}

/**
* Set the value of material
* @param newVar the new value of material
*/
private void setMaterial ( String newVar ) {
material = newVar;
}

/**
* Get the value of material
* @return the value of material
*/
private String getMaterial ( ) {
return material;
}

/**
* Set the value of situacion
* @param newVar the new value of situacion
*/
private void setSituacion ( String newVar ) {
situacion = newVar;
}

/**
* Get the value of situacion
* @return the value of situacion
*/
private String getSituacion ( ) {
return situacion;
}

/**
* Set the value of genero
* @param newVar the new value of genero
*/
private void setGenero ( String newVar ) {
genero = newVar;
}

/**
* Get the value of genero
* @return the value of genero
*/
private String getGenero ( ) {
return genero;
}

/**
* Set the value of clasificacion
* @param newVar the new value of clasificacion
*/
private void setClasificacion ( String newVar ) {
clasificacion = newVar;
}

/**
* Get the value of clasificacion
* @return the value of clasificacion
*/
private String getClasificacion ( ) {
return clasificacion;
}

/**
* Set the value of costoVta
* @param newVar the new value of costoVta
*/
private void setCostoVta ( double newVar ) {
costoVta = newVar;
}

/**
* Get the value of costoVta
* @return the value of costoVta
*/
private double getCostoVta ( ) {
return costoVta;
}

/**
* Set the value of costoRta
* @param newVar the new value of costoRta
*/
private void setCostoRta ( double newVar ) {
costoRta = newVar;
}

/**
* Get the value of costoRta
* @return the value of costoRta
*/
private double getCostoRta ( ) {
return costoRta;
}

/**
* Set the value of cantpel_vta
* @param newVar the new value of cantpel_vta
*/
private void setCantpel_vta ( int newVar ) {
cantpel_vta = newVar;
}

/**
* Get the value of cantpel_vta
* @return the value of cantpel_vta
*/
private int getCantpel_vta ( ) {
return cantpel_vta;
}

/**
* Set the value of cantpel_rta
* @param newVar the new value of cantpel_rta
*/
private void setCantpel_rta ( int newVar ) {
cantpel_rta = newVar;
}

/**
* Get the value of cantpel_rta
* @return the value of cantpel_rta
*/
private int getCantpel_rta ( ) {
return cantpel_rta;
}

//
// Other methods
//

/**
*/
public void vender( )
{
}


/**
*/
public void rentar( )
{
}


/**
*/
public void agregar( )
{
}


/**
*/
public void eliminar( )
{
}


}
Clase Ticket
/**
* Class Ticket
*/
public class Ticket {

//
// Fields
//

protected int no_tick;
protected int cantPeliculas = 0;
protected String fecha;
protected double subtotal;
protected double total;

//
// Constructors
//
public Ticket () { };

//
// Methods
//


//
// Accessor methods
//

/**
* Set the value of no_tick
* @param newVar the new value of no_tick
*/
protected void setNo_tick ( int newVar ) {
no_tick = newVar;
}

/**
* Get the value of no_tick
* @return the value of no_tick
*/
protected int getNo_tick ( ) {
return no_tick;
}

/**
* Set the value of cantPeliculas
* @param newVar the new value of cantPeliculas
*/
protected void setCantPeliculas ( int newVar ) {
cantPeliculas = newVar;
}

/**
* Get the value of cantPeliculas
* @return the value of cantPeliculas
*/
protected int getCantPeliculas ( ) {
return cantPeliculas;
}

/**
* Set the value of fecha
* @param newVar the new value of fecha
*/
protected void setFecha ( String newVar ) {
fecha = newVar;
}

/**
* Get the value of fecha
* @return the value of fecha
*/
protected String getFecha ( ) {
return fecha;
}

/**
* Set the value of subtotal
* @param newVar the new value of subtotal
*/
protected void setSubtotal ( double newVar ) {
subtotal = newVar;
}

/**
* Get the value of subtotal
* @return the value of subtotal
*/
protected double getSubtotal ( ) {
return subtotal;
}

/**
* Set the value of total
* @param newVar the new value of total
*/
protected void setTotal ( double newVar ) {
total = newVar;
}

/**
* Get the value of total
* @return the value of total
*/
protected double getTotal ( ) {
return total;
}

//
// Other methods
//

/**
*/
protected void imprimir( )
{
}


}
Clase TicketVenta
/**
* Class TicketVenta
*/
public class TicketVenta extends Ticket {

//
// Fields
//


//
// Constructors
//
public TicketVenta () { };

//
// Methods
//


//
// Accessor methods
//

//
// Other methods
//

/**
*/
public void imprimir( )
{
}


}
Clase TicketRenta
/**
* Class TicketRenta
*/
public class TicketRenta extends Ticket {

//
// Fields
//

private String fechaLimRta;
private String fechaEntrega;
private double multa;

//
// Constructors
//
public TicketRenta () { };

//
// Methods
//


//
// Accessor methods
//

/**
* Set the value of fechaLimRta
* @param newVar the new value of fechaLimRta
*/
private void setFechaLimRta ( String newVar ) {
fechaLimRta = newVar;
}

/**
* Get the value of fechaLimRta
* @return the value of fechaLimRta
*/
private String getFechaLimRta ( ) {
return fechaLimRta;
}

/**
* Set the value of fechaEntrega
* @param newVar the new value of fechaEntrega
*/
private void setFechaEntrega ( String newVar ) {
fechaEntrega = newVar;
}

/**
* Get the value of fechaEntrega
* @return the value of fechaEntrega
*/
private String getFechaEntrega ( ) {
return fechaEntrega;
}

/**
* Set the value of multa
* @param newVar the new value of multa
*/
private void setMulta ( double newVar ) {
multa = newVar;
}

/**
* Get the value of multa
* @return the value of multa
*/
private double getMulta ( ) {
return multa;
}

//
// Other methods
//

/**
*/
public void imprimir( )
{
}


}
El código auto-generado del esqueleto del proyecto es casi el mismo que el código del esqueleto que yo realice, solamente que en el código auto-generado se utilizan los método get y set para modificar y leer los atributos de cada clase.

Referencias:

Saludos.