Dar las gracias por el aporte a:
Autor: Luis CMurga
Facebook: https://www.facebook.com/luis.cmurga
Descargar proyecto AQUI
¿Que haremos? Crearemos una aplicación en Visual Studio, la cual hará uso de una webcam para capturar el video en frames independientes y depositarlos en memoria para despues mostralos al usuario a través de un picturebox y un Timer para crear la ilusión de movimiento. ¿Porque lo haremos? Porque es justo y necesario ¿Que necesitamos? [...]
JavaMail es una expansión de Java que facilita el envío y recepción de e-mail desde código java. JavaMail implementa el protocolo SMTP (Simple Mail Transfer Protocol) así como los distintos tipos de conexión con servidores de correo -TLS, SSL, autentificación con usuario y password, etc [Según SantaWikipedia] ¿Qué necesitamos? JavaMail 1.4.5 Java y Netbeans 6.9 [...]
En este proyecto realizaremos una aplicación de base de datos Firebird con el lenguaje de programación de Visual Basic de Microsoft, este proyecto tendrá las funciones básicas de gestión INSERT, DELETE, UPDATE y una interfaz de usuario para utilizarlas. ¿Que necesitamos? Visual Studio 2008 o superior Firebird última versión Firebird ADO.NET Data Provider. Conocimientos básicos [...]
La siguiente clase hace uso de PRINT para imprimir una imagen que se encuentra en un variable de tipo FileInputStream, esta clase a su vez es implementada desde una interfaz que hace fácil su uso, la clase así como todo el proyecto esta comentado. import java.io.File; import javax.print.Doc; import java.io.IOException; import javax.print.DocFlavor; import javax.print.SimpleDoc; import java.io.FileInputStream; [...]
JAN29
JAN29
JAN29
-- -- Base de datos: 'dbbolivia' -- -- -- Estructura de tabla para la tabla 'departamento' -- CREATE TABLE departamento ( dep_id int(2) NOT NULL, dep_nombre varchar(32) NOT NULL, PRIMARY KEY (dep_id) ); -- -- Estructura de tabla para la tabla 'provincia' -- CREATE TABLE provincia ( prov_id int(2) NOT NULL auto_increment, prov_nombre varchar(32) NOT NULL, dep_id varchar(32) NOT NULL, PRIMARY KEY (prov_id) ); -- -- Estructura de tabla para la tabla 'municipio' -- CREATE TABLE municipio ( mun_id int(2) NOT NULL auto_increment, mun_nombre varchar(32) NOT NULL, prov_id int(2) NOT NULL, PRIMARY KEY (mun_id) );
import java.sql.*; /** * @web http://www.jc-mouse.net * @author Mouse */ public class database { /* DATOS PARA LA CONEXION */ private String bd = "dbbolivia"; private String login = "";//USUARIO private String password = "";//CONTRASEÑA private String url = "jdbc:mysql://localhost/"+bd; private Connection conn = null; //___________________________________________________________________________________ Soy una barra separadora :) public database(){ try{ //obtenemos el driver de para mysql Class.forName("com.mysql.jdbc.Driver"); //obtenemos la conexión conn = DriverManager.getConnection(url,login,password); if (conn!=null){ System.out.println("OK base de datos "+bd+" listo"); } }catch(SQLException e){ System.out.println(e); }catch(ClassNotFoundException e){ System.out.println(e); } } //___________________________________________________________________________________ Soy una barra separadora :) public Connection getConnection() { return this.conn; } //___________________________________________________________________________________ Soy una barra separadora :) /* METODO PARA REALIZAR UNA CONSULTA A LA BASE DE DATOS * INPUT: * table => nombre de la tabla donde se realizara la consulta, puede utilizarse tambien INNER JOIN * fields => String con los nombres de los campos a devolver Ej.: campo1,campo2campo_n * where => condicion para la consulta * OUTPUT: un object[][] con los datos resultantes, sino retorna NULL */ public Object [][] select(String table, String fields, String where){ int registros = 0; String colname[] = fields.split(","); //Consultas SQL String q ="SELECT " + fields + " FROM " + table; String q2 = "SELECT count(*) as total FROM " + table; if(where!=null) { q+= " WHERE " + where; q2+= " WHERE " + where; } //obtenemos la cantidad de registros existentes en la tabla try{ PreparedStatement pstm = conn.prepareStatement(q2); ResultSet res = pstm.executeQuery(); res.next(); registros = res.getInt("total"); res.close(); }catch(SQLException e){ System.out.println(e); } //se crea una matriz con tantas filas y columnas que necesite Object[][] data = new String[registros][fields.split(",").length]; //realizamos la consulta sql y llenamos los datos en la matriz "Object" try{ PreparedStatement pstm = conn.prepareStatement(q); ResultSet res = pstm.executeQuery(); int i = 0; while(res.next()){ for(int j=0; j<=fields.split(",").length-1;j++){ data[i][j] = res.getString( colname[j].trim() ); } i++; } res.close(); }catch(SQLException e){ System.out.println(e); } return data; } //___________________________________________________________________________________ Soy una barra separadora :) }
import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath;
private database db = new database();
public interfaz() { initComponents(); this.setTitle("JTree - http://www.jc-mouse.net/"); //se crea la raiz DefaultMutableTreeNode pais = new DefaultMutableTreeNode("Bolivia"); DefaultMutableTreeNode departamento; DefaultMutableTreeNode provincia; DefaultMutableTreeNode municipio; //se obtienen los departamentos Object[][] data_dep = db.select("departamento", " dep_id, dep_nombre", null); if( data_dep.length > 0) { for(int i=0; i < data_dep.length; i++) { //se crea hojas departamentos departamento = new DefaultMutableTreeNode(data_dep[i][1]); pais.add(departamento); //se obtiene las provincias Object[][] data_prov = db.select("provincia", "prov_id,prov_nombre" , " dep_id='" + data_dep[i][0].toString()+"' "); if( data_prov.length > 0) { for(int j=0; j< data_prov.length; j++) { provincia = new DefaultMutableTreeNode(data_prov[j][1]); departamento.add(provincia); //se obtienen los municipios Object[][] data_mun = db.select("municipio", "mun_id,mun_nombre" , " prov_id='" + data_dep[j][0].toString()+"' "); if( data_mun.length > 0) { for(int k=0; k< data_mun.length; k++) { municipio = new DefaultMutableTreeNode(data_mun[k][1]); provincia.add(municipio); } } } } } } DefaultTreeModel modelo = new DefaultTreeModel(pais); this.jTree1.setModel(modelo); jTree1.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { // Se obtiene el Path seleccionado TreePath path = e.getPath(); Object [] nodos = path.getPath(); String txt= jTextArea1.getText() + "Path seleccionado: "; for (Object nodo: nodos) txt+=nodo.toString() + " | "; txt+="\n"; // Se obtiene el Nodo seleccionado DefaultMutableTreeNode NodoSeleccionado = (DefaultMutableTreeNode)nodos[nodos.length-1]; txt+="-> Accion para Nodo Seleccionado [" + NodoSeleccionado.getUserObject().toString() + "]"; txt+="\n"; jTextArea1.setText(txt); } }); }
JAN29
JAN29
// <editor-fold> El codigo va aqui // </editor-fold>
// <editor-fold desc="Este codigo es importantisimo"> codigo aqui // </editor-fold>
JAN29
<html> <style type="text/css"> .estilo1{font-family:Bradley Hand ITC;font-weight:bold; font-size:24px;color:rgb(51, 51, 51);} .estilo2{font-family:Rod;font-weight:bold; font-size:12px;color:rgb(102, 102, 102);} </style> <span class="estilo1">Boton Fachero</span><br/> <span class="estilo2">Problem?</span> </html>
JAN29
01 package model; 02 /** 03 * @web http://jc-mouse.blogspot.com/ 04 * @author Mouse 05 * En esta clase se guarda la lógica del sistema, para este sencillo ejemplo 06 * consiste en una SUMA 07 */ 08 public class modelo { 09 //Variables 10 private int valor1=28; 11 private int valor2=69; 12 private int total = sumar(); 13 14 public modelo(){} 15 16 public void set_valor1(int val){ 17 this.valor1=val; 18 } 19 20 public int get_valor1(){ 21 return this.valor1; 22 } 23 24 public void set_valor2(int val){ 25 this.valor2=val; 26 } 27 28 public int get_valor2(){ 29 return this.valor2; 30 } 31 32 public int sumar(){ 33 this.total = this.valor1 + this.valor2; 34 return this.total; 35 } 36 37 public int get_total(){ 38 return this.total; 39 } 40 41 }
01 package controller; 02 03 import java.awt.event.ActionEvent; 04 import java.awt.event.ActionListener; 05 import model.modelo; 06 import view.vista; 07 /** 08 * @web http://jc-mouse.blogspot.com/ 09 * @author Mouse 10 */ 11 public class controlador implements ActionListener{ 12 13 private vista vista; 14 private modelo modelo; 15 16 //En el constructor inicializamos nuestros objetos y tambien 17 //añadimos el ActionListener al boton "cmdsumar" de la VISTA 18 public controlador( vista vista , modelo modelo){ 19 this.vista = vista; 20 this.modelo = modelo; 21 this.vista.cmdsumar.addActionListener(this); 22 } 23 24 //Inicia los valores del jFrame VISTA con los datos del MODELO 25 public void iniciar_vista(){ 26 vista.setTitle( "Demo MVC * jc-mouse.net" ); 27 vista.setLocationRelativeTo(null); 28 vista.vtxt1.setText( String.valueOf(modelo.get_valor1()) ); 29 vista.vtxt2.setText( String.valueOf(modelo.get_valor2()) ); 30 vista.vtxt3.setText( String.valueOf(modelo.get_total()) ); 31 } 32 33 //La accion del boton de la VISTA es capturado, asi como los valores de 34 //los jtextbox, entonces se realiza la funcion SUMAR y se actualiza 35 //el jtextbox correspondiente al resultado 36 public void actionPerformed(ActionEvent e) { 37 modelo.set_valor1( Integer.valueOf( vista.vtxt1.getText() ) ); 38 modelo.set_valor2( Integer.valueOf( vista.vtxt2.getText() ) ); 39 modelo.sumar(); 40 vista.vtxt3.setText( String.valueOf(modelo.get_total()) ); 41 } 42 43 }
01 package jc_mvc_demo; 02 03 import controller.controlador; 04 import model.modelo; 05 import view.vista; 06 /** 07 * @web http://jc-mouse.blogspot.com/ 08 * @author Mouse 09 */ 10 public class Main { 11 12 public static void main(String[] args) { 13 14 //nuevas instancias de clase 15 modelo modelo = new modelo(); 16 vista vista = new vista(); 17 controlador controlador = new controlador( vista , modelo ); 18 //se inicia la vista 19 controlador.iniciar_vista(); 20 21 vista.setVisible(true); 22 23 } 24 25 }
JAN29
JAN29
import java.util.logging.Level; import java.util.logging.Logger; import javax.media.*; import javax.media.cdm.CaptureDeviceManager; import java.io.*; import java.awt.*; import javax.media.control.FrameGrabbingControl; import javax.media.format.VideoFormat; import javax.media.util.BufferToImage; import javax.swing.JLabel; import javax.swing.JOptionPane; /** * @web http://jc-mouse.blogspot.com/ * @author Mouse */ public class jmfVideo { //Controlador universal de windows private String dispositivo = "vfw:Microsoft WDM Image Capture (Win32):0"; private Player player = null; public Component Componente(){ Component componente_video; try { // Se obtiene el dispositivo CaptureDeviceInfo device = CaptureDeviceManager.getDevice(dispositivo); //se obtiene la fuente de datos de captura MediaLocator localizador = device.getLocator(); //El localizador es del tipo "vfw://0" video para windows //se crea el PLAYER y se ejecuta player = Manager.createRealizedPlayer(localizador); player.start(); } catch (IOException ex) { Logger.getLogger(jmfVideo.class.getName()).log(Level.SEVERE, null, ex); } catch (NoPlayerException ex) { Logger.getLogger(jmfVideo.class.getName()).log(Level.SEVERE, null, ex); } catch (CannotRealizeException ex) { Logger.getLogger(jmfVideo.class.getName()).log(Level.SEVERE, null, ex); } //Si se pudo crear el PLAYER, se obtiene el componente de video if ((componente_video = player.getVisualComponent()) != null) { //se da un tamaño al componente componente_video.setSize(320, 240); return componente_video; } else { JOptionPane.showMessageDialog(null,"No se pudo crear el video..."); return null; } } //Metodo para capturar la imagen de la webcam Image img = null; public void capturarImagen(){ FrameGrabbingControl ControlFG = (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl"); Buffer buffer = ControlFG.grabFrame(); // creamos la imagen awt BufferToImage imagen = new BufferToImage((VideoFormat)buffer.getFormat()); img = imagen.createImage(buffer); } public Image getImagen(){ return img; } public void setImage(JLabel lb){ capturarImagen(); lb.setIcon( new javax.swing.ImageIcon( img ) ); System.out.println("ancho= " + img.getWidth(null)); System.out.println("alto= " + img.getHeight(null)); } }
jmfVideo b = new jmfVideo(); /** Creates new form video */ public video() { initComponents(); this.setTitle("Captura de Imagen desde WebCam - by Mouse"); //formulario al centro de la pantalla this.setLocationRelativeTo(null); //se coloca un layout tipo CAJA VIDEO.setLayout(new javax.swing.BoxLayout(VIDEO, javax.swing.BoxLayout.LINE_AXIS)); //se añade el componente de video VIDEO.add(b.Componente()); imagen.setText(""); }
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { b.capturarImagen(); jcSlide1.setImagen(new ImageIcon(b.getImagen())); } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { if( jcSlide1.getImagen() != null ){ imagen.setIcon( jcSlide1.getImagen() ); }else{ JOptionPane.showMessageDialog(this,"Por favor. Debe seleccionar una imagen..."); } }
![]() |
![]() |
![]() |
![]() |