El 21 marzo, 2013 ·
0 Comentarios
Programa en Java que emula el clasico juego de atari Space Invaders (Invasion del Espacio), fue realizado usando la plataforma NetBeans y AWT.
Nombre del Programa: Space Invaders.
Version del Programa: NA.
Autor(es): Jose Gonzalez, Luis Molina, Eulis Blanco.
Lenguaje en que fue programado: Java 1.6.x/1.7.x.
Licencia bajo la que fue liberado: Creative Commons Reconocimiento-NoComercial-CompartirIgual 3.0.
Fecha de lanzamiento: Febrero 2013.
Idioma(s): NA.
Captura de pantalla del programa ejecutándose:
Código:
SpaceInvaders.java
package spaceinvaders ;
import javax.swing.JFrame ;
public class Spaceinvaders extends JFrame {
public Spaceinvaders( ) {
add( new Juego( ) ) ;
setDefaultCloseOperation( JFrame .EXIT_ON_CLOSE ) ;
setSize( 500 , 500 ) ;
setLocationRelativeTo( null ) ;
setTitle( "Space Invaders" ) ;
setResizable( false ) ;
setVisible( true ) ;
}
public static void main( String [ ] args) {
new Spaceinvaders( ) ;
}
}
Juego.java
package spaceinvaders ;
import java.awt.Color ;
import java.awt.Font ;
import java.awt.FontMetrics ;
import java.awt.Graphics ;
import java.awt.Graphics2D ;
import java.awt.Rectangle ;
import java.awt.Toolkit ;
import java.awt.event.ActionEvent ;
import java.awt.event.ActionListener ;
import java.awt.event.KeyAdapter ;
import java.awt.event.KeyEvent ;
import java.util.ArrayList ;
import javax.swing.JFrame ;
import javax.swing.JPanel ;
import javax.swing.Timer ;
/**
*
* @author JOSE GONZALEZ
*/
public class Juego extends JPanel implements ActionListener {
private Timer timer;
private long tiempomax;
private long contador;
private long tiempoanterior;
private Nave nave;
private boolean ingame;
private int ANCHO;
private int ALTO;
private String msg;
private Misil misil_alien;
private int vidas = 2 ;
private ArrayList aliens;
private int [ ] [ ] pos = {
{ 130 , 29 } ,{ 180 , 29 } ,{ 230 , 29 } ,{ 280 , 29 } ,{ 330 , 29 } ,
{ 105 , 59 } ,{ 155 , 59 } ,{ 205 , 59 } ,{ 255 , 59 } ,{ 305 , 59 } ,{ 355 , 59 } ,
{ 130 , 89 } ,{ 180 , 89 } ,{ 230 , 89 } ,{ 280 , 89 } ,{ 330 , 89 } ,
{ 105 , 119 } ,{ 155 , 119 } ,{ 205 , 119 } ,{ 255 , 119 } ,{ 305 , 119 } ,{ 355 , 119 } ,
} ;
public Juego( ) { //contrustor inicialisa variable
addKeyListener( new TAdapter( ) ) ;
setFocusable( true ) ;
setBackground( Color .BLACK ) ;
setDoubleBuffered( true ) ;
ingame = true ;
msg = "Game Over" ;
setSize( 500 , 500 ) ;
nave = new Nave( 225 , 400 ,500 ) ;
iniciarAliens( ) ;
misil_alien = new Misil( 0 ,0 ) ;
misil_alien.setVisible ( false ) ;
tiempomax = 1000 ; //tiempo movimiento de aliens ms
contador = 0 ; //durasion de cada frame
timer = new Timer ( 5 , this ) ; //cada 5ms ejecuta el metodo accionperforment necesita implementar action listener
timer.start ( ) ;
}
public void addNotify( ) {
super .addNotify ( ) ;
this .ALTO = getHeight( ) ;
this .ANCHO = getWidth( ) ;
}
public void iniciarAliens( ) { //aliens crea
aliens = new ArrayList ( ) ;
for ( int i= 0 ; i& lt; pos.length ; i++ ) {
aliens.add ( new Alien( pos[ i] [ 0 ] , pos[ i] [ 1 ] ) ) ;
}
}
public void paint( Graphics g) { //pintar o graficar
super .paint ( g) ;
if ( ingame) {
Graphics2D g2d = ( Graphics2D ) g;
if ( nave.isVisible ( ) )
g2d.drawImage ( nave.getImage ( ) , nave.getX ( ) , nave.getY ( ) ,this ) ; //dibuja imagen
ArrayList ms = nave.getMisiles ( ) ;
for ( int i = 0 ; i & lt; ms.size ( ) ; i++ ) { //recorre array, dibuja el misil
Misil m = ( Misil) ms.get ( i) ;
g2d.drawImage ( m.getImage ( ) , m.getX ( ) , m.getY ( ) , this ) ;
}
for ( int i = 0 ; i & lt; aliens.size ( ) ; i++ ) { Alien a = ( Alien) aliens.get ( i) ; if ( a.isVisible ( ) ) { g2d.drawImage ( a.getImage ( ) , a.getX ( ) , a.getY ( ) , this ) ; } } g2d.drawImage ( misil_alien.getImage ( ) , misil_alien.getX ( ) , misil_alien.getY ( ) , this ) ; g2d.setColor ( Color .WHITE ) ; g2d.drawString ( "Vidas: " + vidas, 5 , 15 ) ; g2d.drawString ( "Hasta Aqui -> " , 5 , 250 ) ;
g2d.drawString ( "________________________________________________________________________________________" , 0 , 450 ) ;
}
if ( ! ingame) {
Font small = new Font ( "Helvetica" , Font .BOLD , 14 ) ;
FontMetrics metr = this .getFontMetrics ( small) ;
g.setColor ( Color .white ) ;
g.setFont ( small) ;
g.drawString ( msg, ( ANCHO - metr.stringWidth ( msg) ) / 2 ,
ALTO / 2 ) ;
}
g.dispose ( ) ;
}
public void actionPerformed( ActionEvent e) { //logica
if ( aliens.size ( ) == 0 ) {
ingame = false ;
msg = "GANASTE" ;
}
ArrayList ms = nave.getMisiles ( ) ;
for ( int i = 0 ; i & lt; ms.size ( ) ; i++ ) { //misil borrar, mover Misil m = (Misil) ms.get(i); if (m.isVisible()) m.mover(); else ms.remove(i); } long delta = System.currentTimeMillis()- tiempoanterior;// timemillis tiempo del programa completo, tiempo de kda frame tiempoanterior = System.currentTimeMillis();//tiempo del ultimo frame del anterior contador += delta;//suma la duracion del nuevo frame if (contador > tiempomax) {
contador = 0 ;
for ( int i = 0 ; i & lt; aliens.size ( ) ; i++ ) { //esto lo ase en un solo frame
Alien a = ( Alien) aliens.get ( i) ;
a.mover ( ) ;
}
}
for ( int i = 0 ; i & lt; aliens.size ( ) ; i++ ) { //remueve en el frame q sigue Alien a = (Alien) aliens.get(i); if (!a.isVisible()) aliens.remove(i); } if(misil_alien.visible == false){//alien alazar y dispara double numero = Math.floor(Math.random()*aliens.size()); int k = (int) numero; Alien ad = (Alien) aliens.get(k); misil_alien = ad.fire(); } misil_alien.mover_alien(); nave.mover(); checkearColisiones(); repaint(); } public void checkearColisiones() { Rectangle r3 = nave.getBounds(); Rectangle r4 = misil_alien.getBounds(); if(r3.intersects(r4)){ nave.setVisible(false); misil_alien.setVisible(false); vidas--; if(vidas>=0){
nave.setPos ( 50 , 400 ) ;
nave.setVisible ( true ) ;
} else {
ingame = false ;
}
}
for ( int j = 0 ; j& lt; aliens.size ( ) ; j++ ) { Alien a = ( Alien) aliens.get ( j) ; Rectangle r2 = a.getBounds ( ) ; if ( r2.y + r2.height & gt; 250 ) {
ingame = false ;
}
}
ArrayList ms = nave.getMisiles ( ) ;
for ( int i = 0 ; i & lt; ms.size ( ) ; i++ ) {
Misil m = ( Misil) ms.get ( i) ;
Rectangle r1 = m.getBounds ( ) ;
for ( int j = 0 ; j& lt; aliens.size ( ) ; j++ ) {
Alien a = ( Alien) aliens.get ( j) ;
Rectangle r2 = a.getBounds ( ) ;
if ( r1.intersects ( r2) ) {
m.setVisible ( false ) ;
a.setVisible ( false ) ;
}
}
}
}
private class TAdapter extends KeyAdapter { //cactura teclas
public void keyReleased( KeyEvent e) {
nave.keyReleased ( e) ;
}
public void keyPressed( KeyEvent e) {
nave.keyPressed ( e) ;
}
}
}
Nave.java
package spaceinvaders ;
import java.awt.Image ;
import java.awt.Rectangle ;
import java.awt.event.KeyEvent ;
import java.util.ArrayList ;
import javax.swing.ImageIcon ;
/**
*
* @author JOSE GONZALEZ
*/
public class Nave {
private String Nave = "spaceship1.png" ;
private int dx;
private int x;
private int y;
private int ancho;
private int alto;
private boolean visible;
private Image imagen;
private ArrayList misiles;
private int anchocanvas;
public Nave( int posX, int posY,int anchocanva) {
ImageIcon ii = new ImageIcon ( this .getClass ( ) .getResource ( Nave) ) ; //oa agarra el archivo
imagen = ii.getImage ( ) ;
ancho = imagen.getWidth ( null ) ;
alto = imagen.getHeight ( null ) ;
misiles = new ArrayList ( ) ;
visible = true ;
x = posX;
y = posY;
anchocanvas= anchocanva;
}
public void mover( ) {
x += dx;
if ( x & lt; 1 ) { x = 1 ; } if ( x& gt;= anchocanvas- ancho) {
x= anchocanvas- ancho;
}
}
public void setPos( int x, int y) {
this .x = x;
this .y = y;
}
public int getX( ) {
return x;
}
public int getY( ) {
return y;
}
public Image getImage( ) {
return imagen;
}
public void setVisible( boolean visible) {
this .visible = visible;
}
public boolean isVisible( ) {
return visible;
}
public ArrayList getMisiles( ) {
return misiles;
}
public Rectangle getBounds( ) {
return new Rectangle ( x, y, ancho, alto) ;
}
public void keyPressed( KeyEvent e) {
int key = e.getKeyCode ( ) ;
if ( key == KeyEvent .VK_SPACE ) {
disparar( ) ;
}
if ( key == KeyEvent .VK_LEFT ) {
dx = - 1 ;
}
if ( key == KeyEvent .VK_RIGHT ) {
dx = 1 ;
}
}
public void disparar( ) {
if ( misiles.size ( ) & lt; 5 ) {
misiles.add ( new Misil( ( x + ancho/ 2 ) - 2 , y) ) ;
}
}
public void keyReleased( KeyEvent e) {
int key = e.getKeyCode ( ) ;
if ( key == KeyEvent .VK_LEFT ) {
dx = 0 ;
}
if ( key == KeyEvent .VK_RIGHT ) {
dx = 0 ;
}
}
}
Alien.java
package spaceinvaders ;
import java.awt.Image ;
import java.awt.Rectangle ;
import java.awt.event.KeyEvent ;
import java.util.ArrayList ;
import javax.swing.ImageIcon ;
/**
*
* @author JOSE GONZALEZ
*/
public class Alien {
private String alien = "alien1.png" ;
private int dx;
private int dy;
private int x;
private int y;
private int movimientos_max;
private int movimientos_hechos;
private int ciclos_max;
private int ciclos;
private int ancho;
private int alto;
private boolean visible;
private Image imagen;
private ArrayList misiles;
public Alien( int posX, int posY) {
ImageIcon ii = new ImageIcon ( this .getClass ( ) .getResource ( alien) ) ;
imagen = ii.getImage ( ) ;
ancho = imagen.getWidth ( null ) ;
alto = imagen.getHeight ( null ) ;
visible = true ;
x = posX;
y = posY;
dx = 10 ;
dy = 10 ;
movimientos_max = 6 ;
movimientos_hechos = movimientos_max/ 2 ;
ciclos_max = 2 ;
ciclos = 0 ;
misiles = new ArrayList ( ) ;
}
public void mover( ) {
x += dx;
movimientos_hechos++;
if ( movimientos_hechos & gt;= movimientos_max) {
dx *= - 1 ;
movimientos_hechos = 0 ;
ciclos++;
if ( ciclos& gt;= ciclos_max) {
mover_abajo( ) ;
ciclos= 0 ;
}
}
}
public void mover_abajo( ) {
y += dy;
}
public int getX( ) {
return x;
}
public int getY( ) {
return y;
}
public Image getImage( ) {
return imagen;
}
public ArrayList getMisiles( ) {
return misiles;
}
public void setVisible( boolean visible) {
this .visible = visible;
}
public boolean isVisible( ) {
return visible;
}
public Rectangle getBounds( ) {
return new Rectangle ( x, y, ancho, alto) ;
}
public Misil fire( ) {
return new Misil( ( x + ancho/ 2 ) - 2 , y + alto) ;
}
}
Misil.java
package spaceinvaders ;
import java.awt.Image ;
import java.awt.Rectangle ;
import javax.swing.ImageIcon ;
/**
*
* @author JOSE GONZALEZ
*/
public class Misil {
private int x, y;
private Image imagen;
boolean visible;
private int ancho, alto;
private final int VELOCIDAD_MISIL = 6 ;
public Misil( int x, int y) {
ImageIcon ii= new ImageIcon ( this .getClass ( ) .getResource ( "missile.png" ) ) ;
imagen = ii.getImage ( ) ;
visible = true ;
ancho = imagen.getWidth ( null ) ;
alto = imagen.getHeight ( null ) ;
this .x = x;
this .y = y;
}
public Image getImage( ) {
return imagen;
}
public int getX( ) {
return x;
}
public int getY( ) {
return y;
}
public boolean isVisible( ) {
return visible;
}
public void setVisible( Boolean visible) {
this .visible = visible;
}
public Rectangle getBounds( ) {
return new Rectangle ( x, y, ancho, alto) ;
}
public void mover( ) {
y -= VELOCIDAD_MISIL;
if ( y & lt; 5 )
visible = false ;
}
public void mover_alien( ) {
y += VELOCIDAD_MISIL/ 2 ;
if ( y & gt; 450 - alto)
visible = false ;
}
}
Imagenes usadas en el programa:
https://www.safecreative.org/work/1302164602724-alien1
https://www.safecreative.org/work/1302164602717-missile
https://www.safecreative.org/work/1302164602700-spaceship1
https://www.safecreative.org/work/1302164602694-spaceshiphd1
El 21 mayo, 2011 ·
0 Comentarios
Nombre del Programa: SharkTube
Versión del Programa: 1.1 ( Renaissance )
Autor(es): Sebastián Castaño (.:WindHack:.)
Sistema Operativos: Multiplataforma.
- Lenguaje en que fue programado: Python 2.6.x
Licencia bajo la que fue liberado: Creative Commons Reconocimiento-NoComercial-CompartirIgual 3.0 , Ver Registro en SafeCreative.org
Fecha de lanzamiento: 12 de abril de 2011
Idioma(s): Español/Inglés
Funcionalidad/Tópico del Programa: Script para descargar directamente vídeos de YouTube.
Captura de pantalla del programa ejecutándose:
Para ver la información completa y los enlaces de descarga, clic AQUÍ.
El 21 mayo, 2011 ·
0 Comentarios
Este es un pequeño tip para quitar la flecha que se muestra en un acceso directo. Es muy sencillo y el resultado es agradable.
Para ver el tutorial clic AQUÍ.
El 21 mayo, 2011 ·
1 Comentario
En este tutorial se enseña a instalar los componentes necesarios para monitorear la temperatura de nuestro equipo.
Para ver el tutorial clic AQUÍ.
El 21 mayo, 2011 ·
0 Comentarios
Un sencillo tutorial en el cual se explica de manera rápida y efectiva la forma de crear una USB booteable para instalar el sistema operativo Windows .
Para ver el tutorial clic AQUÍ.
El 24 marzo, 2011 ·
0 Comentarios
Nombre del Programa: WS Downloader
Versión del Programa: 0.1 (Beta)
Autor(es): Sebastián Castaño (.:WindHack:.) y Carlos Sánchez (swik)
Sistema Operativos: Multiplataforma.
- Lenguaje en que fue programado: Python 2.6.x
Licencia bajo la que fue liberado: Creative Commons Reconocimiento-NoComercial-CompartirIgual 3.0 , Ver Registro en SafeCreative.org
Fecha de lanzamiento: 17 de noviembre de 2010
Idioma(s): Español
Funcionalidad/Tópico del Programa: Script para descargar directamente vídeos de YouTube.
Captura de pantalla del programa ejecutándose: NA
Código:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# WS Downloader.py - v0.1 (Beta)
# Autor(es): .:WindHack:. & swik
# :www.daw-labs.com | :www.cibernodo.net
# Registrado en SafeCreative
# Licencia: Creative Commons Reconocimiento-NoComercial-CompartirIgual 3.0
# 17/11/2010
import sys , urllib , os
#
# @Charset
#
Char = [ '%3A' , '%2F' , '%26' , '%2C' , '%3D' , '%252C' , '%253A' , '%7C' , '%3F' ]
By = [ ':' , '/' , '&' , ',' , '=' , ',' , ':' , '' , '?' ]
#
# URLDecode(sURL)
# Descifra la URL teniendo en cuenta el Charset.
#
def URLDecode( sURL) :
for i in range ( len ( Char) ) :
sURL = sURL.replace ( Char[ i] , By[ i] )
return sURL
#
# GetSourceCode(sURL)
# Obtiene el código de fuente del vídeo (sitio).
#
def GetSourceCode( sURL) :
try :
URL = urllib .urlopen ( sURL)
sSource = URL.read ( )
URL.close ( )
return sSource
except :
print 'Error de conexión.'
exit( )
#
# GetIndexVideo(sSource,Tags)
# Obtiene la posición de un "Tag" o etiqueta.
#
def GetIndexVideo( sSource, Tags) :
return sSource.find ( Tags)
#
# GetVideoTitle(sSource)
# Obtiene el título del vídeo.
#
def GetVideoTitle( sSource) :
sSource = sSource[ 2000 :5500 ]
Begin = GetIndexVideo( sSource, '
El 24 marzo, 2011 ·
3 Comentarios
Sudokux es una aplicación en Java, capaz de resolver en menos de un segundo cualquier sudoku que le propongas.
Nombre del Programa: Sudokux.
Versión del Programa: 1.0.
Autor(es): Pablo Martínez Insua (pablomi).
Sistema Operativo: Multiplataforma.
Lenguaje en que fue programado: Java 1.6.x.
Licencia bajo la que fue liberado: Creative Commons Reconocimiento-NoComercial-CompartirIgual 3.0. Ver registro en Safe Creative .
Fecha de lanzamiento: 06 – 09 – 2010.
Idioma(s): Español.
Captura:
Código:
import java.awt.* ;
import java.awt.event.* ;
import javax.swing.* ;
import java.io.* ;
// Sudokux 1.0 - Pablo Martínez Insua
//
// Programa registrado.
// Licencia: -http://creativecommons.org/licenses/by-nc-sa/3.0/deed.es_PE
public class Sudokux {
private static int [ ] [ ] casilla;
JFrame ventana = new JFrame ( "Sudokux 1.0" ) ;
JMenuBar menus = new JMenuBar ( ) ;
JMenu menuArchivo = new JMenu ( "Archivo" ) ;
JMenu menuHelp = new JMenu ( "Ayuda" ) ;
JMenuItem archivoSalir = new JMenuItem ( "Salir" ) ;
JMenuItem helpAcercaDe = new JMenuItem ( "Acerca de" ) ;
Font fontRespuesta = new Font ( "Verdana" , Font .BOLD , 20 ) ;
JButton resolver = new JButton ( "Resolver" ) ;
JButton borrar = new JButton ( "Borrar" ) ;
JTextField numeros[ ] [ ] = new JTextField [ 10 ] [ 10 ] ;
String solucion;
public static void main( String [ ] args) {
casilla = new int [ 10 ] [ 10 ] ;
for ( int col= 0 ; col< 9 ; col++ )
for ( int fil= 0 ; fil< 9 ; fil++ )
casilla[ fil] [ col] = 0 ;
Sudokux mostrarVentana = new Sudokux( ) ;
}
public Sudokux( ) {
configurar( ) ;
acciones( ) ;
}
void configurar( ) {
menuArchivo.add ( archivoSalir) ;
menuHelp.add ( helpAcercaDe) ;
menus.add ( menuArchivo) ;
menus.add ( menuHelp) ;
for ( int i= 1 ; i< 10 ; i++ ) {
for ( int j= 1 ; j< 10 ; j++ ) {
numeros[ i] [ j] = new JTextField ( 1 ) ;
ventana.add ( numeros[ i] [ j] ) ;
numeros[ i] [ j] .setFont ( fontRespuesta) ;
}
}
ventana.add ( menus) ;
ventana.setJMenuBar ( menus) ;
ventana.add ( resolver) ;
ventana.add ( borrar) ;
ventana.setVisible ( true ) ;
ventana.setSize ( 300 , 420 ) ;
ventana.setDefaultCloseOperation ( JFrame .EXIT_ON_CLOSE ) ;
ventana.setLayout ( new FlowLayout ( FlowLayout .CENTER ) ) ;
}
void acciones( ) {
archivoSalir.addActionListener ( new ActionListener ( ) {
public void actionPerformed( ActionEvent e) {
System .exit ( 0 ) ;
}
} ) ;
helpAcercaDe.addActionListener ( new ActionListener ( ) {
public void actionPerformed( ActionEvent e) {
JOptionPane .showMessageDialog ( null , "Programa: Sudokux\n Autor: Pablo Martínez Insua\n Versión: 1.0" , "Acerca de" , JOptionPane .INFORMATION_MESSAGE ) ;
}
} ) ;
resolver.addMouseListener ( new MouseAdapter ( ) {
public void mousePressed( MouseEvent e) {
recoger_datos( ) ;
resuelve( 1 ,1 ) ;
for ( int col= 1 ; col< 10 ; col++ ) {
for ( int fil= 1 ; fil< 10 ; fil++ ) {
numeros[ fil] [ col] .setText ( "" + casilla[ fil] [ col] ) ;
}
}
}
} ) ;
borrar.addMouseListener ( new MouseAdapter ( ) {
public void mousePressed( MouseEvent e) {
for ( int col= 1 ; col< 10 ; col++ ) {
for ( int fil= 1 ; fil< 10 ; fil++ ) {
numeros[ fil] [ col] .setText ( "" ) ;
casilla[ fil] [ col] = 0 ;
}
}
}
} ) ;
}
void recoger_datos( ) {
int tiene = 1 ;
for ( int col= 1 ; col< 10 ; col++ ) {
for ( int fil= 1 ; fil< 10 ; fil++ ) {
if ( ! numeros[ fil] [ col] .getText ( ) .equals ( "" ) )
casilla[ fil] [ col] = Integer .parseInt ( numeros[ fil] [ col] .getText ( ) ) ;
tiene = 0 ;
}
}
if ( tiene== 1 ) {
JOptionPane .showMessageDialog ( null , "Introduce el sudoku a resolver." , "Error" , JOptionPane .WARNING_MESSAGE ) ;
}
}
private static boolean resuelve( int fil, int col) {
boolean resuelto = false , casillaSegura = false ;
int num = 1 ;
if ( casilla[ fil] [ col] != 0 )
{
casillaSegura = true ;
num= 9 ;
}
while ( ! resuelto && num< 10 )
{
if ( ! casillaSegura)
casilla[ fil] [ col] = num;
if ( es_valida( fil,col) )
{
if ( fil== 9 && col== 9 )
resuelto = true ;
else if ( fil< 9 )
resuelto = resuelve( fil+ 1 , col) ;
else if ( fil== 9 )
resuelto = resuelve( 1 , col+ 1 ) ;
}
num++;
}
if ( ! resuelto && ! casillaSegura)
casilla[ fil] [ col] = 0 ;
return resuelto;
}
private static boolean es_valida( int fil, int col) {
for ( int i= 1 ; i< 10 ; i++ )
if ( fil!= i && casilla[ fil] [ col] == casilla[ i] [ col] )
return false ;
for ( int i= 1 ; i< 10 ; i++ )
if ( col!= i && casilla[ fil] [ col] == casilla[ fil] [ i] )
return false ;
int cuadroColumna = ( int ) ( Math .floor ( ( col- 1 ) / 3 ) * 3 ) + 1 ,
cuadroFila = ( int ) ( Math .floor ( ( fil- 1 ) / 3 ) * 3 ) + 1 ;
for ( int i= cuadroColumna; i< cuadroColumna + 3 ; i++ )
for ( int j= cuadroFila; j< cuadroFila+ 3 ; j++ )
if ( col!= i && fil!= j && casilla[ fil] [ col] == casilla[ j] [ i] )
return false ;
return true ;
}
}
El 24 marzo, 2011 ·
0 Comentarios
Goxar es un editor de texto plano con las funciones tipicas de uno de este. Carece de menu de edición. En su versión 1.0 cuenta con funciones de abrir, guardar.
Nombre del Programa: Goxar Editor de texto plano.
Versión del Programa: 1.0.
Autor(es): Carlos Sánchez (swik).
Sistema Operativo: Windows XP SP3.
Lenguaje en que fue programado: Python 2.6.x.
Licencia bajo la que fue liberado: Creative Commons Reconocimiento-NoComercial-CompartirIgual 3.0 .
Fecha de lanzamiento: 28/8/10.
Idioma(s): Español.
Capturas:
Código:
#-*- coding: iso-8859-1 -*-
#Goxar editor
#Agradecimientos a Sifaw
#Copyright © 2010
#Autor: swik
#Bajo licencia
import wx, os
ID_OPEN = 5000
ID_NEW = 5002
ID_SAVE = 5003
ID_SaveAS = 5004
ID_EXIT = 5006
ID_ABOUT = 5014
class Editor( wx.MiniFrame ) :
def __init__ ( self ) :
wx.MiniFrame .__init__ ( self , None , -1 , 'Goxar Editor' , wx.DefaultPosition , ( 900 , 700 ) , ( wx.DEFAULT_FRAME_STYLE ) ^( wx.RESIZE_BORDER |wx.MAXIMIZE_BOX ) )
panel = wx.Panel ( self , wx.NewId ( ) , wx.DefaultPosition , ( 900 , 700 ) )
self .edit = wx.TextCtrl ( panel, size= ( 900 , 700 ) , style= wx.TE_MULTILINE )
self .CreateStatusBar ( )
self .SetStatusText ( "Barra de estado - Goxar Editor de texto plano" )
#-----------------------------------------------------------------------
menubar = wx.MenuBar ( )
#menu de archivo
archi = wx.Menu ( )
archi.Append ( ID_NEW, 'Nuevo' , 'Limpia el contenido para comenzar un archivo nuevo' )
archi.Append ( -2 , '' , '' )
archi.Append ( ID_OPEN, 'Abrir' , 'Abre un archivo' )
archi.Append ( ID_SAVE, 'Guardar' , 'Guarda el archivo previamente guardado' )
archi.Append ( ID_SaveAS, 'Guardar como' , 'Guarda el archivo' )
archi.Append ( -2 , '' , '' )
archi.Append ( ID_EXIT, 'Salir' , 'Sale del programa' )
#menu de ayuda
ayu = wx.Menu ( )
ayu.Append ( ID_ABOUT, 'Acerca de...' , 'Mas informacion acerca del programa' )
#eventos
wx.EVT_MENU ( self , wx.ID_EXIT , self .onClose )
wx.EVT_MENU ( self , wx.ID_ABOUT , self .onAbout )
wx.EVT_MENU ( self , wx.ID_OPEN , self .onOpen )
wx.EVT_MENU ( self , wx.ID_SAVEAS , self .onSaveAS )
wx.EVT_MENU ( self , wx.ID_SAVE , self .onSave )
wx.EVT_MENU ( self , wx.ID_NEW , self .onNew )
#barra de menu
menubar.Append ( archi, '&Archivo' )
menubar.Append ( ayu, '&Ayuda' )
self .SetMenuBar ( menubar)
#----------------------------------------------------------------------
#cerrar
def onClose( self , *event) :
self .Close ( True )
#acerca de
def onAbout( self , e) :
dlg1 = wx.MessageDialog ( self , "Goxar Editor de texto plano v1.0" , "" , wx.OK )
dlg2 = wx.MessageDialog ( self , "Copyright © 2010 " , "" , wx.OK )
dlg1.ShowModal ( )
dlg2.ShowModal ( )
dlg1.Destroy ( )
dlg2.Destroy ( )
#abrir
def onOpen( self , event) :
self .dirname = ''
dlg = wx.FileDialog ( self , "Goxar: Abrir" , self .dirname , "" , "*.*" , wx.OPEN )
if dlg.ShowModal ( ) == wx.ID_OK :
self .filename = dlg.GetFilename ( )
self .dirname = dlg.GetDirectory ( )
a = open ( self .filename , 'r' )
self .edit .SetValue ( a.read ( ) )
self .edit .write ( self .filename )
def onSaveAS( self , event) :
self .dirname = ''
dlg1 = wx.FileDialog ( self , "Goxar: Guardar como" , self .dirname , "" , "*.*" , wx.SAVE | wx.OVERWRITE_PROMPT )
if dlg1.ShowModal ( ) == wx.ID_OK :
conten = self .edit .GetValue ( )
self .filename = dlg1.GetFilename ( )
self .dirname = dlg1.GetDirectory ( )
filehandle= open ( os .path .join ( self .dirname , self .filename ) , 'w' )
filehandle.write ( conten)
filehandle.close ( )
dlg1.Destroy ( )
def onSave( self , event) :
grab = self .edit .GetValue ( )
a = open ( self .filename , 'w' )
a.write ( grab)
a.close ( )
def onNew( self , event) :
self .edit .Clear ( )
class App( wx.App ) :
def OnInit( self ) :
frame = Editor( )
frame.Show ( )
self .SetTopWindow ( frame)
return True
if __name__ == '__main__' :
app = App( )
app.MainLoop ( )
El 24 marzo, 2011 ·
0 Comentarios
Servlet encargado de recibir una petición POST desde un formulario html y verificar la información recibida en una base de datos mysql, usando para ello el conector jdbc. Si la información es correcta, crea una cookie en el navegador y carga la pagina que deseemos, de ser falsa, carga otra pagina. (Cambios mínimos en el código son requeridos).
Nombre del Programa: Servlet DataBase.
Versión del Programa: NA.
Autor(es): Oswaldo Gutierrez (-Gosw-) y Widnelzy Salas (yuyiwid).
Sistema Operativos: Windows XP SP3.
Lenguaje en que fue programado: Java 1.6.x.
Licencia bajo la que fue liberado: Creative Commons Reconocimiento-NoComercial-CompartirIgual 3.0 , Ver Registro en SafeCreative.org .
Fecha de lanzamiento: 14 de Octubre del 2009.
Idioma(s): NA.
Captura de pantalla del programa ejecutándose: NA.
Código:
import javax.servlet.* ;
import javax.servlet.http.* ;
import java.io.* ;
import java.util.* ;
import java.sql.* ;
public class ServletDataBase extends HttpServlet
{
static String login = "User" ;
static String password = "Password" ;
static String url = "jdbc:mysql://localhost:3306/BaseDeDatos" ;
@Override
public void init( ServletConfig conf) throws ServletException
{
super .init ( conf) ;
}
@Override
protected void doPost( HttpServletRequest peticion, HttpServletResponse respuesta) throws ServletException, IOException
{
String usuario = peticion.getParameter ( "usuario" ) ; //vendra del formulario
String pass = peticion.getParameter ( "pass" ) ; //vendra del formulario
Connection conexion = null ; //Objeto para la conexión a la BD
Statement sentencia = null ; //Objeto para la ejecutar una sentencia
ResultSet resultados = null ; //Objeto para guardar los resultados
Cookie[ ] cks = peticion.getCookies ( ) ;
respuesta.setContentType ( "text/html" ) ;
PrintWriter salida = respuesta.getWriter ( ) ;
try
{
//Leemos el driver JDBC
Class .forName ( "com.mysql.jdbc.Driver" ) ;
//Nos conectamos a la BD
conexion = DriverManager .getConnection ( url,login,password) ;
//Creamos una sentencia a partir de la conexión
sentencia= conexion.createStatement ( ) ;
//Tomamos todos los datos de la asignaturas
resultados= sentencia.executeQuery ( "SELECT user,password FROM usuarios" ) ;
//Preguntamos si existe Usuario
while ( resultados.next ( ) )
{
if ( usuario.equals ( resultados.getString ( "user" ) ) && pass.equals ( resultados.getString ( "password" ) ) )
{
if ( cks == null )
{
Cookie LogCedea = new Cookie( "Usuario" ,usuario) ;
LogCedea.setMaxAge ( 900 ) ;
LogCedea.setPath ( "/CarpetaDeAplicacion" ) ;
respuesta.addCookie ( LogCedea) ;
salida.println ( "<?xml version = \" 1.0\" ?>" ) ;
salida.println ( "<!DOCTYPE HTML PUBLIC \" -//W3C//DTD HTML 4.01 Transitional//EN\" \" http://www.w3.org/TR/html4/loose.dtd\" >" ) ;
salida.println ( "<html xmlns = \" http://www.w3.org/1999/xhtml\" >" ) ;
salida.println ( "<head>" ) ;
salida.println ( "<title>Login Correcto</title>" ) ;
salida.println ( "<meta http-equiv=\" Refresh\" content=\" 3;url=http://La_Direccion_que_desees_que_llame\" >" ) ;
salida.println ( "</head>" ) ;
salida.println ( "<body>" ) ;
salida.println ( "<br />
<h1>Bienvenido</h1>
<p>" ) ;
salida.println ( "<br />
<h3>Espere la Redireccion</h3>
<p>" ) ;
salida.println ( "</body>" ) ;
salida.println ( "</html>" ) ;
salida.close ( ) ;
}
else
{
salida.println ( "<?xml version = \" 1.0\" ?>" ) ;
salida.println ( "<!DOCTYPE HTML PUBLIC \" -//W3C//DTD HTML 4.01 Transitional//EN\" \" http://www.w3.org/TR/html4/loose.dtd\" >" ) ;
salida.println ( "<html xmlns = \" http://www.w3.org/1999/xhtml\" >" ) ;
salida.println ( "<head>" ) ;
salida.println ( "<title>Login Correcto</title>" ) ;
salida.println ( "<meta http-equiv=\" Refresh\" content=\" 3;url=http://La_Direccion_que_desees_que_llame\" >" ) ;
salida.println ( "</head>" ) ;
salida.println ( "<body>" ) ;
salida.println ( "<br />
<h1>Bienvenido</h1>
<p>" ) ;
salida.println ( "<br />
<h3>Espere la Redireccion</h3>
<p>" ) ;
salida.println ( "</body>" ) ;
salida.println ( "</html>" ) ;
salida.close ( ) ;
}
}
}
salida.println ( "<?xml version = \" 1.0\" ?>" ) ;
salida.println ( "<!DOCTYPE HTML PUBLIC \" -//W3C//DTD HTML 4.01 Transitional//EN\" \" http://www.w3.org/TR/html4/loose.dtd\" >" ) ;
salida.println ( "<html xmlns = \" http://www.w3.org/1999/xhtml\" >" ) ;
salida.println ( "<head>" ) ;
salida.println ( "<title>Login Incorrecto</title>" ) ;
salida.println ( "<meta http-equiv=\" Refresh\" content=\" 3;url=http://La_Direccion_que_desees_que_llame\" >" ) ;
salida.println ( "</head>" ) ;
salida.println ( "<body>" ) ;
salida.println ( "<br />
<h1>Usuario o Clave Incorrectos, por favor intente de nuevo</h1>
<p>" ) ;
salida.println ( "<br />
<h3>Espere la Redireccion</h3>
<p>" ) ;
salida.println ( "</body>" ) ;
salida.println ( "</html>" ) ;
salida.close ( ) ;
}
catch ( ClassNotFoundException e1)
{
salida.println ( "No se encontró el driver de la BD: " + e1.getMessage ( ) ) ;
}
catch ( SQLException e2)
{
salida.println ( "Fallo en SQL: " + e2.getMessage ( ) ) ;
}
finally
{
try
{
if ( conexion!= null )
conexion.close ( ) ;
}
catch ( SQLException e3)
{
salida.println ( "Fallo al desconectar SQL: " + e3.getMessage ( ) ) ;
}
}
}
@Override
protected void doGet( HttpServletRequest peticion, HttpServletResponse respuesta) throws ServletException, IOException
{
doPost( peticion, respuesta) ;
}
}
El 24 marzo, 2011 ·
0 Comentarios
Aplicación para la descarga de archivos de música desde internet.
Nombre: Metáfora Music Downloader.
Version: 2.0.
Autor: Fernando Gómez (Sifaw).
Sistemas Operativos: Multiplataforma. Programado bajo MacOSX por lo que en los demás sistemas puede tener fallos estéticos.
Lenguaje: Python 2.5.4.
Licencia: Creative Commons Reconocimiento-NoComercial-CompartirIgual 3.0 .
Fecha de lanzamiento: 22/08/10.
Idioma: Español.
Capturas:
Video:
VIDEO
Código:
#importamos los modulos
#! /usr/bin/python
import wx
import thread
import urllib as u
class Busqueda( wx.Panel ) :
def __init__ ( self , panel) :
#Colocamos los botones
wx.Panel .__init__ ( self , panel)
self .search = wx.SearchCtrl ( self , size= ( 300 , -1 ) , style= wx.TE_PROCESS_ENTER )
self .search .ShowCancelButton ( True )
npag = wx.StaticText ( self , label= 'N de paginas' )
self .pag = wx.SearchCtrl ( self , size= ( 50 , -1 ) , style= wx.TE_PROCESS_ENTER )
self .pag .SetValue ( '0' )
self .pag .ShowSearchButton ( False )
canc = wx.StaticBox ( self , label= 'Lista de canciones' , size= ( 290 , 225 ) )
self .lista = wx.ListBox ( self , size= ( 280 , 215 ) , style= wx.LB_SINGLE )
topsizer = wx.BoxSizer ( wx.HORIZONTAL )
topsizer.Add ( self .search , 0 , wx.ALL |wx.EXPAND , 3 )
middlesizer = wx.BoxSizer ( wx.HORIZONTAL )
middlesizer.Add ( npag, 0 , wx.ALL , 3 )
middlesizer.Add ( self .pag , 0 , wx.ALL , 3 )
footsizer = wx.StaticBoxSizer ( canc, wx.VERTICAL )
footsizer.Add ( self .lista , 0 , wx.ALL , 0 )
totalsizer = wx.BoxSizer ( wx.VERTICAL )
totalsizer.Add ( topsizer, 0 , wx.ALL |wx.EXPAND , 3 )
totalsizer.Add ( middlesizer, 0 , wx.ALL |wx.ALIGN_RIGHT , 3 )
totalsizer.Add ( footsizer, 0 , wx.ALL , 3 )
self .SetSizer ( totalsizer)
totalsizer.Fit ( self )
self .lista .Bind ( wx.EVT_LEFT_DCLICK , self .eleccion )
self .Bind ( wx.EVT_SEARCHCTRL_CANCEL_BTN , self .cancelbusca , self .search )
self .Bind ( wx.EVT_SEARCHCTRL_SEARCH_BTN , self .cargar , self .search )
self .Bind ( wx.EVT_TEXT_ENTER , self .cargar , self .search )
def cancelbusca( self , event) :
self .search .SetValue ( '' )
def eleccion( self , event) :
pg2.listdesc .Append ( self .lista .GetString ( self .lista .GetSelection ( ) ) , self .lista .GetClientData ( self .lista .GetSelection ( ) ) )
def cargar( self , event) :
#Nos conectamos a goear y realizamos la busqueda selccionada mostrandolo en el listbox
pag = int ( self .pag .GetValue ( ) )
busqueda = ''
for i in self .search .GetValue ( ) :
if i == ' ' :
busqueda += '+'
else :
busqueda += i
self .lista .Clear ( )
n = 0
while n <= pag:
web = u.urlopen ( 'http://www.goear.com/search.php?q=%s&p=%i' % ( busqueda, n) )
web = web.read ( )
i = web.find ( 'Escuchar' )
fin = False
url = False
canciones = [ ]
lugar = [ ]
but = ''
can = 0
while fin != True :
while web[ i:i+8 ] != 'Escuchar' :
i += 1
while url == False :
i += 1
if ( web[ i] == '"' ) and ( web[ i+1 ] == 'l' ) :
url = True
i += 1
while web[ i] != '"' :
but += web[ i]
i += 1
lugar.append ( but)
but = ''
while web[ i] != '>' :
i += 1
i += 1
while web[ i] != '<' :
but += web[ i]
i += 1
canciones.append ( but)
self .lista .Append ( canciones[ 0 ] , lugar[ 0 ] )
but = ''
canciones = [ ]
lugar = [ ]
url = False
can += 1
if can == 10 :
fin = True
n += 1
class Descarga( wx.Panel ) :
def __init__ ( self , panel) :
wx.Panel .__init__ ( self , panel)
self .descact = False
self .barra = wx.Gauge ( self , -1 , size= ( 297 , -1 ) )
self .descbtn = wx.Button ( self , -1 , 'Descargar' )
dsc = wx.StaticBox ( self , label= 'Lista de descarga' , pos= ( 5 , 55 ) , size= ( 290 , 240 ) )
self .listdesc = wx.ListBox ( self , pos= ( 10 , 75 ) , size= ( 280 , 221 ) , style= wx.LB_SINGLE )
topsizer = wx.BoxSizer ( wx.HORIZONTAL )
topsizer.Add ( self .barra , 0 , wx.ALL |wx.ALIGN_CENTER_HORIZONTAL , 3 )
middle = wx.BoxSizer ( wx.HORIZONTAL )
mid = wx.BoxSizer ( wx.HORIZONTAL )
mid.Add ( wx.StaticLine ( self , -1 , size= ( 97 , -1 ) ) , 0 , wx.ALL |wx.EXPAND , 3 )
mid.Add ( self .descbtn , 0 , wx.ALL , 3 )
mid.Add ( wx.StaticLine ( self , -1 , size= ( 97 , -1 ) ) , 0 , wx.ALL |wx.EXPAND , 3 )
foot = wx.StaticBoxSizer ( dsc, wx.HORIZONTAL )
foot.Add ( self .listdesc , 0 , wx.ALL , 0 )
total = wx.BoxSizer ( wx.VERTICAL )
total.Add ( topsizer, 0 , wx.ALL , 3 )
total.Add ( middle, 0 , wx.ALL , 3 )
total.Add ( mid, 0 , wx.ALL |wx.EXPAND |wx.ALIGN_CENTER_HORIZONTAL , 3 )
total.Add ( foot, 0 , wx.ALL , 3 )
self .SetSizer ( total)
total.Fit ( self )
self .listdesc .Bind ( wx.EVT_LEFT_DCLICK , self .eliminarlist )
self .Bind ( wx.EVT_BUTTON , self .activardesc , self .descbtn )
def activardesc( self , event) :
if self .descbtn .Label == 'Descargar' :
thread .start_new_thread ( self .descargar , ( ) )
self .descact = True
self .descbtn .Label = 'Cancelar'
else :
self .descact = False
self .descbtn .Label = 'Descargar'
def descargar( self ) :
#Buscamos el link de descarga y descargamos la eleccion escogida
while self .descact :
try :
self .barra .Pulse ( )
web = u.urlopen ( 'http://www.videofindr.net/goear/?url=http://goear.com/%s' % self .listdesc .GetClientData ( 0 ) )
web = web.read ( )
tam = len ( web)
i = web.find ( 'http:' )
url = ''
while web[ i] != '"' :
url += web[ i]
i += 1
u.urlretrieve ( url, "%s.mp3" % self .listdesc .GetString ( 0 ) , reporthook= self .progresodesc )
self .listdesc .Delete ( 0 )
self .barra .SetRange ( 0 )
self .barra .SetValue ( 0 )
except :
self .barra .SetRange ( 0 )
self .barra .SetValue ( 0 )
self .descact = False
self .descbtn .Label = 'Descargar'
def progresodesc( self , bloque, tamano, total) :
self .barra .SetRange ( total)
totaldesc = bloque * tamano
self .barra .SetValue ( totaldesc)
def eliminarlist( self , event) :
try :
self .listdesc .Delete ( self .listdesc .GetSelection ( ) )
except :
pass
class Frame( wx.Frame ) :
def __init__ ( self ) :
#Frame en el que se veran los widgets a partir de dos pestanas
wx.Frame .__init__ ( self , None , -1 , title= "Metafora Music Downloader" , pos= wx.DefaultPosition ,
size= ( 315 , 390 ) ,
style= wx.DEFAULT_FRAME_STYLE ^( wx.RESIZE_BORDER |wx. MAXIMIZE_BOX ) )
panel = wx.Panel ( self )
nb = wx.Notebook ( panel)
pg1 = Busqueda( nb)
global pg2
pg2 = Descarga( nb)
nb.AddPage ( pg1, "Busqueda" )
nb.AddPage ( pg2, "Descarga" )
sizer = wx.BoxSizer ( wx.VERTICAL )
sizer.Add ( nb, 1 , wx.EXPAND )
panel.SetSizer ( sizer)
self .SetExtraStyle ( wx.FRAME_EX_METAL )
self .Center ( )
class App( wx.App ) :
def OnInit( self ) :
frame = Frame( )
frame.Show ( )
self .SetTopWindow ( frame)
return True
if __name__ == '__main__' :
app = App( )
app.MainLoop ( )