Leng Prog II Grabar y Leer Imagnes

13
   UNIVERSIDAD NACIONAL TECNOLÓGICA DEL CONO SUR DE LIMA ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS LENGUAJE DE PROGRAMACION II Docente: Ing. D íaz Leyva Teodoro Tema:  Guardar y Leer Imágenes en MySQL  Introducción Muchas veces necesitamos guardar la ruta de un archivo. Por ejemplo si es un programa para llevar el control de empleados tal vez será necesario guardar las fotografías de los empleados o una imagen de un producto, o la ruta de un archivo de document o, etc. En este laboratorio se crea una aplicación para guardar la ruta de un archivo de imagen en una tabla de MySQL y recuperarla. El tipo de dato utilizado en MySQL para almacenar archivos de imagen es el BLOB, es un objeto binario que puede tratar una cantidad de datos variables. Los cuatro tipos BLOB son TINYBLOB, BLOB, MEDIUMBLOB y LONGBLOB. Difieren sólo en la longitud máxima de los valores que pueden tratar. Las columnas  BLOB se tratan como cadenas de caracteres binarias (de bytes). Recordar que un archivo es una secuencia de bytes que se guarda en disco y que puede actuar como origen o como destino de un flujo. Los bytes no tienen ningún formato ni tamaño de registro. El programador es el encargado de ordenar y darle sentido a esa secuencia . La clase FileInputStream es una clase específica que obtiene bytes de un archivo. En su constructor recibe como argumento el nombre físico de un archivo y crea un flujo de bytes.

description

Grabar y leer imagenes

Transcript of Leng Prog II Grabar y Leer Imagnes

Page 1: Leng Prog II Grabar y Leer Imagnes

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 112

983120983265983143983145983150983137 983089 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

LENGUAJE DE PROGRAMACION II

Docente Ing Diacuteaz Leyva Teodoro

Tema Guardar y Leer Imaacutegenes en MySQL

Introduccioacuten

Muchas veces necesitamos guardar la ruta de un archivo Por ejemplo si es un

programa para llevar el control de empleados tal vez seraacute necesario guardar las

fotografiacuteas de los empleados o una imagen de un producto o la ruta de un archivo de

documento etc En este laboratorio se crea una aplicacioacuten para guardar la ruta de un

archivo de imagen en una tabla de MySQL y recuperarla

El tipo de dato utilizado en MySQL para almacenar archivos de imagen es el BLOB

es un objeto binario que puede tratar una cantidad de datos variables Los cuatro tipos

BLOB son TINYBLOB BLOB MEDIUMBLOB y LONGBLOB Difieren soacutelo en la

longitud maacutexima de los valores que pueden tratar Las columnas BLOB se tratan como

cadenas de caracteres binarias (de bytes)

Recordar que un archivo es una secuencia de bytes que se guarda en disco y que

puede actuar como origen o como destino de un flujo Los bytes no tienen ninguacuten

formato ni tamantildeo de registro El programador es el encargado de ordenar y darle

sentido a esa secuencia

La clase FileInputStream es una clase especiacutefica que obtiene bytes de un archivo En

su constructor recibe como argumento el nombre fiacutesico de un archivo y crea un flujo de

bytes

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 212

983120983265983143983145983150983137 983090 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

1 Crear base de datos ldquoacademiardquo en ella crear la siguiente tabla

Tabla alumno

Campo Tipo de dato

Id int auto_increment

Nombres varchar(60)

Apellidos varchar(60)

foto LONGBLOB

2 En Netbeans crear proyecto ldquoLPII_Imagenes_BD

3 Crear los siguientes paquetes y clases

Programar en las clases

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 312

983120983265983143983145983150983137 983091 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

4 Clase conexioacuten

package pecomacademiaconexion

import javasqlConnectionimport javasqlDriverManagerimport javasqlSQLException

public class Conexion variablesprivate Connection cn=nullprivate String us=rootprivate String clave=123private String url=jdbcmysqllocalhostacademia

-----------------------------------------------------------public Connection abrir()try

registrar driverClassforName(commysqljdbcDriver)

cn=DriverManagergetConnection(url us clave) catch (SQLException ex)

Systemoutprintf(Error en la conexion +exgetMessage())

catch (ClassNotFoundException ex) Systemoutprintf(Error al cargar driver+exgetMessage())

finallyreturn cn

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 412

983120983265983143983145983150983137 983092 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

5 Clase AlumnoVO

package pecomacademiabeanpublic class AlumnoVO

variables datos o camposprivate int idprivate String nombresprivate String apellidosprivate String foto

metodos set y get -----------------------------------------------------------------

public String getApellidos()

return apellidos

public void setApellidos(String apellidos) thisapellidos = apellidos

public String getFoto() return foto

public void setFoto(String foto)

thisfoto = foto

public int getId() return id

public void setId(int id) thisid = id

public String getNombres()

return nombres

public void setNombres(String nombres) thisnombres = nombres

fin de la clase

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 512

983120983265983143983145983150983137 983093 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

6 Clase AlumnoDao

package pecomacademiadaoimport javaawtImageimport javaioFileimport javaioFileInputStreamimport javaioIOExceptionimport javasqlimport pecomacademiabeanAlumnoVOimport pecomacademiaconexionConexion

public class AlumnoDao extends Conexion

public String grabarAlumno(AlumnoVO alumnoVO)

variablesString mensaje=nullConnection cn=nullPreparedStatement psFileInputStream fis ------------------------------------------------------------------------------ cadena sql para insertar datos a la tabla alumnoString sql = INSERT INTO alumno(nombresapellidosfoto) VALUES () abrir conexion metodo de la clase conexion esta aqui por herencia a dicha clasecn= abrir() ------------------------------------------------------------------------------try

ps = cnprepareStatement(sql)pssetString(1 alumnoVOgetNombres())pssetString(2 alumnoVOgetApellidos())

ruta puede ser cimagenesfotojpgFile filefoto = new File(alumnoVOgetFoto())

La clase FileInputStream se utiliza para leer bytes desde un archivofis = new FileInputStream(filefoto)

pssetBinaryStream(3 fisfisavailable())

psexecuteUpdate()

catch (IOException | SQLException ex) mensaje=exgetMessage()

return mensajefin del metodo grabaralumno

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 612

983120983265983143983145983150983137 983094 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

-------------------------------------------------------------------------------------------------------public Image buscarAlumno( int codigo ) throws SQLException IOException

Image rpta=nullConnection cn=nullcn=abrir()

String sql = SELECT FROM alumno where id=+codigo +

Statement stmt = cncreateStatement()ResultSet results = stmtexecuteQuery(sql)Blob imagen=nullif(resultsnext())

imagen = resultsgetBlob(foto) Esta parte es clave donde se convierte a imagenrpta= javaximageioImageIOread(imagengetBinaryStream())

return rpta

fin del meacutetodo buscarAlumno

public AlumnoVO getDatosAlumno( int codigo ) throws SQLExceptionIOException

Image rpta=nullConnection cn=nullcn=abrir()

String sql = SELECT FROM alumno where id=+codigo +

Statement stmt = cncreateStatement()ResultSet rs = stmtexecuteQuery(sql)AlumnoVO alumnoVO=nullif(rsnext())

alumnoVO=new AlumnoVO()alumnoVOsetNombres(rsgetString(nombres))alumnoVOsetApellidos(rsgetString(apellidos))

return alumnoVO

fin del meacutetodo getDatosAlumnofin de la clase AlumnoDao

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 712

983120983265983143983145983150983137 983095 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

7 Clase Registraralumno RecuperarFoto Principal

package pecomacademiapresentacionimport javaawtBorderLayoutimport javaawtColorimport javaawtImageimport javaawteventActionEvent

import javaawteventActionListenerimport javaioFileimport javaxswingimport javaxswingborderBorderimport javaxswingfilechooserFileNameExtensionFilterimport pecomacademiabeanAlumnoVOimport pecomacademiadaoAlumnoDao

public class Registraralumno extends JPanel implements ActionListener

Extension de imagenprivate FileNameExtensionFilter filtro = new FileNameExtensionFilter(Archivo de

ImagenjpgpngJPGjpgGIFgif) -------------------------------------------------------------------------------------------------------- variablesprivate String mensaje=nullprivate JPanel panel=nullprivate JLabel lblcodigoprivate JLabel lblnombresprivate JLabel lblapellidosprivate JLabel lblimagenprivate JLabel lblfotoprivate JTextField txtcodigoprivate JTextField txtnombres

private JTextField txtapellidosprivate JTextField txtfotoprivate JButton btnnuevoprivate JButton btnagregarprivate JButton btnbuscarprivate JButton btnexaminar

private File fileprivate JFileChooser fileChooserprivate Image foto

AlumnoVO alumnoVO=null

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 812

983120983265983143983145983150983137 983096 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

----------------------------------------------------------------------- constructor

public Registraralumno () panelsetLayout( new BorderLayout())panel=new JPanel()panelsetLayout(null)panelsetBackground(new Color(100 160 120))

-----------------------------------------------------------------------lblcodigo=new JLabel(Id)lblcodigosetBounds(10 40 60 20)lblnombres=new JLabel(Nombres)lblnombressetBounds(10 90 60 20)

lblapellidos=new JLabel(Apellidos)lblapellidossetBounds(10 140 60 20)lblfoto=new JLabel(Foto)lblfotosetBounds(10 190 60 20)txtcodigo=new JTextField()txtcodigosetBounds(7040 50 20)txtnombres=new JTextField()txtnombressetBounds(70 90 220 20)txtapellidos=new JTextField()txtapellidossetBounds(70 140 220 20)txtfoto=new JTextField()txtfotosetBounds(70 190 220 20)btnexaminar=new JButton(Examinar)btnexaminarsetBounds(295 190150 20)lblimagen=new JLabel()

borde a la etiqueta lblimagenBorder border=BorderFactorycreateLineBorder(Colorwhite)lblimagensetBorder(border)lblimagensetBounds(300 10 190 170)btnnuevo=new JButton(Nuevo) btnnuevosetBounds(10 240 9020)btnagregar=new JButton(Agregar) btnagregarsetBounds(100 240 9020)

btnbuscar=new JButton(Ver Foto) btnbuscarsetBounds(190 240 9020)

------------------------------------------------------------------------paneladd(lblcodigo)paneladd(lblnombres)paneladd(lblapellidos)paneladd(txtcodigo)paneladd(txtnombres)paneladd(txtapellidos)paneladd(txtfoto)

paneladd(btnnuevo)paneladd(btnagregar)

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 912

983120983265983143983145983150983137 983097 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

paneladd(btnverfoto)paneladd(btnexaminar)

paneladd(lblimagen)paneladd(lblfoto)

add(panelBorderLayoutCENTER)setSize(400 400)setVisible(true)

-----------------------------------------------------------------------btnexaminaraddActionListener(this)btnagregaraddActionListener(this)btnbuscaraddActionListener(this)

fin del constructor

-----------------------------------------------------------------------public void AbrirDialogo()

fileChooser=new JFileChooser()

filtrar archivos con exrensiones permitidasfileChoosersetFileFilter(filtro)int resultado=fileChoosershowOpenDialog(this)

if(resultado==JFileChooserAPPROVE_OPTION)file=fileChoosergetSelectedFile()txtfotosetText(filetoString())foto=getToolkit()getImage(txtfotogetText())foto=fotogetScaledInstance(200 20050)lblimagensetIcon(new ImageIcon(foto))

fin abrirDialogo

----------------------------------------------------------------------- metodo de la interfaz ActionListener

Overridepublic void actionPerformed(ActionEvent e)

if(egetSource()==btnexaminar)

AbrirDialogo()if(egetSource()==btnagregar)

AlumnoDao alumnoDao=new AlumnoDao()asignarDatos()mensaje= alumnoDaograbarAlumno(alumnoVO)

if (mensaje==null)cudroMensaje(Datos de alumno registrado)

elsecudroMensaje(Error +mensaje)

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1012

983120983265983143983145983150983137 983089983088 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

if(egetSource()==btnbuscar)Buscaralumno rf=new Buscaralumno()

rfshow()

fin del metodo actionPerformed

---------------------------------------------------------------------- encapsular datos en el objeto alumnoVOpublic void asignarDatos()

alumnoVO=new AlumnoVO()alumnoVOsetNombres(txtnombresgetText())alumnoVOsetApellidos(txtapellidosgetText())alumnoVOsetFoto(txtfotogetText())

fin del metodo AsignarDatos

public void cudroMensaje(String mensaje)JOptionPaneshowMessageDialog(null mensaje)

fin de la clase Presentacion

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1112

983120983265983143983145983150983137 983089983089 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

(Se utilizoacute el asistente para crear este formulario)

private void txtcodigoKeyPressed(javaawteventKeyEvent evt) if(evtgetKeyCode()==evtVK_ENTER)

Image fotoAlumnoDao a=new AlumnoDao()

try AlumnoVO alumnoVO=agetDatosAlumno(IntegerparseInt(txtcodigogetText()))

setTitle(alumnoVOgetNombres()+ +alumnoVOgetApellidos())

foto=abuscarAlumno(IntegerparseInt(txtcodigogetText()))

foto=fotogetScaledInstance(300 300ImageSCALE_DEFAULT)

lblvistaFotosetIcon(new ImageIcon(foto))

thissetLocationRelativeTo(null)

catch (SQLException ex)

catch (IOException ex)

txtcodigo

lblvistaFoto

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1212

983120983265983143983145983150983137 983089983090 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

package pecomacademiapresentacion

import javaawtBorderLayoutimport javaxswingJFrame

public class Principal extends JFramepublic Principal()

getContentPane()add(new Registraralumno () BorderLayoutCENTER)meacutetodo principal

public static void main(String []args)Principal p=new Principal()psetTitle(Alumno)psetSize(700 400)psetLocationRelativeTo(null)psetVisible(true)

fin del meacutetodo principal

Page 2: Leng Prog II Grabar y Leer Imagnes

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 212

983120983265983143983145983150983137 983090 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

1 Crear base de datos ldquoacademiardquo en ella crear la siguiente tabla

Tabla alumno

Campo Tipo de dato

Id int auto_increment

Nombres varchar(60)

Apellidos varchar(60)

foto LONGBLOB

2 En Netbeans crear proyecto ldquoLPII_Imagenes_BD

3 Crear los siguientes paquetes y clases

Programar en las clases

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 312

983120983265983143983145983150983137 983091 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

4 Clase conexioacuten

package pecomacademiaconexion

import javasqlConnectionimport javasqlDriverManagerimport javasqlSQLException

public class Conexion variablesprivate Connection cn=nullprivate String us=rootprivate String clave=123private String url=jdbcmysqllocalhostacademia

-----------------------------------------------------------public Connection abrir()try

registrar driverClassforName(commysqljdbcDriver)

cn=DriverManagergetConnection(url us clave) catch (SQLException ex)

Systemoutprintf(Error en la conexion +exgetMessage())

catch (ClassNotFoundException ex) Systemoutprintf(Error al cargar driver+exgetMessage())

finallyreturn cn

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 412

983120983265983143983145983150983137 983092 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

5 Clase AlumnoVO

package pecomacademiabeanpublic class AlumnoVO

variables datos o camposprivate int idprivate String nombresprivate String apellidosprivate String foto

metodos set y get -----------------------------------------------------------------

public String getApellidos()

return apellidos

public void setApellidos(String apellidos) thisapellidos = apellidos

public String getFoto() return foto

public void setFoto(String foto)

thisfoto = foto

public int getId() return id

public void setId(int id) thisid = id

public String getNombres()

return nombres

public void setNombres(String nombres) thisnombres = nombres

fin de la clase

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 512

983120983265983143983145983150983137 983093 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

6 Clase AlumnoDao

package pecomacademiadaoimport javaawtImageimport javaioFileimport javaioFileInputStreamimport javaioIOExceptionimport javasqlimport pecomacademiabeanAlumnoVOimport pecomacademiaconexionConexion

public class AlumnoDao extends Conexion

public String grabarAlumno(AlumnoVO alumnoVO)

variablesString mensaje=nullConnection cn=nullPreparedStatement psFileInputStream fis ------------------------------------------------------------------------------ cadena sql para insertar datos a la tabla alumnoString sql = INSERT INTO alumno(nombresapellidosfoto) VALUES () abrir conexion metodo de la clase conexion esta aqui por herencia a dicha clasecn= abrir() ------------------------------------------------------------------------------try

ps = cnprepareStatement(sql)pssetString(1 alumnoVOgetNombres())pssetString(2 alumnoVOgetApellidos())

ruta puede ser cimagenesfotojpgFile filefoto = new File(alumnoVOgetFoto())

La clase FileInputStream se utiliza para leer bytes desde un archivofis = new FileInputStream(filefoto)

pssetBinaryStream(3 fisfisavailable())

psexecuteUpdate()

catch (IOException | SQLException ex) mensaje=exgetMessage()

return mensajefin del metodo grabaralumno

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 612

983120983265983143983145983150983137 983094 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

-------------------------------------------------------------------------------------------------------public Image buscarAlumno( int codigo ) throws SQLException IOException

Image rpta=nullConnection cn=nullcn=abrir()

String sql = SELECT FROM alumno where id=+codigo +

Statement stmt = cncreateStatement()ResultSet results = stmtexecuteQuery(sql)Blob imagen=nullif(resultsnext())

imagen = resultsgetBlob(foto) Esta parte es clave donde se convierte a imagenrpta= javaximageioImageIOread(imagengetBinaryStream())

return rpta

fin del meacutetodo buscarAlumno

public AlumnoVO getDatosAlumno( int codigo ) throws SQLExceptionIOException

Image rpta=nullConnection cn=nullcn=abrir()

String sql = SELECT FROM alumno where id=+codigo +

Statement stmt = cncreateStatement()ResultSet rs = stmtexecuteQuery(sql)AlumnoVO alumnoVO=nullif(rsnext())

alumnoVO=new AlumnoVO()alumnoVOsetNombres(rsgetString(nombres))alumnoVOsetApellidos(rsgetString(apellidos))

return alumnoVO

fin del meacutetodo getDatosAlumnofin de la clase AlumnoDao

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 712

983120983265983143983145983150983137 983095 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

7 Clase Registraralumno RecuperarFoto Principal

package pecomacademiapresentacionimport javaawtBorderLayoutimport javaawtColorimport javaawtImageimport javaawteventActionEvent

import javaawteventActionListenerimport javaioFileimport javaxswingimport javaxswingborderBorderimport javaxswingfilechooserFileNameExtensionFilterimport pecomacademiabeanAlumnoVOimport pecomacademiadaoAlumnoDao

public class Registraralumno extends JPanel implements ActionListener

Extension de imagenprivate FileNameExtensionFilter filtro = new FileNameExtensionFilter(Archivo de

ImagenjpgpngJPGjpgGIFgif) -------------------------------------------------------------------------------------------------------- variablesprivate String mensaje=nullprivate JPanel panel=nullprivate JLabel lblcodigoprivate JLabel lblnombresprivate JLabel lblapellidosprivate JLabel lblimagenprivate JLabel lblfotoprivate JTextField txtcodigoprivate JTextField txtnombres

private JTextField txtapellidosprivate JTextField txtfotoprivate JButton btnnuevoprivate JButton btnagregarprivate JButton btnbuscarprivate JButton btnexaminar

private File fileprivate JFileChooser fileChooserprivate Image foto

AlumnoVO alumnoVO=null

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 812

983120983265983143983145983150983137 983096 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

----------------------------------------------------------------------- constructor

public Registraralumno () panelsetLayout( new BorderLayout())panel=new JPanel()panelsetLayout(null)panelsetBackground(new Color(100 160 120))

-----------------------------------------------------------------------lblcodigo=new JLabel(Id)lblcodigosetBounds(10 40 60 20)lblnombres=new JLabel(Nombres)lblnombressetBounds(10 90 60 20)

lblapellidos=new JLabel(Apellidos)lblapellidossetBounds(10 140 60 20)lblfoto=new JLabel(Foto)lblfotosetBounds(10 190 60 20)txtcodigo=new JTextField()txtcodigosetBounds(7040 50 20)txtnombres=new JTextField()txtnombressetBounds(70 90 220 20)txtapellidos=new JTextField()txtapellidossetBounds(70 140 220 20)txtfoto=new JTextField()txtfotosetBounds(70 190 220 20)btnexaminar=new JButton(Examinar)btnexaminarsetBounds(295 190150 20)lblimagen=new JLabel()

borde a la etiqueta lblimagenBorder border=BorderFactorycreateLineBorder(Colorwhite)lblimagensetBorder(border)lblimagensetBounds(300 10 190 170)btnnuevo=new JButton(Nuevo) btnnuevosetBounds(10 240 9020)btnagregar=new JButton(Agregar) btnagregarsetBounds(100 240 9020)

btnbuscar=new JButton(Ver Foto) btnbuscarsetBounds(190 240 9020)

------------------------------------------------------------------------paneladd(lblcodigo)paneladd(lblnombres)paneladd(lblapellidos)paneladd(txtcodigo)paneladd(txtnombres)paneladd(txtapellidos)paneladd(txtfoto)

paneladd(btnnuevo)paneladd(btnagregar)

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 912

983120983265983143983145983150983137 983097 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

paneladd(btnverfoto)paneladd(btnexaminar)

paneladd(lblimagen)paneladd(lblfoto)

add(panelBorderLayoutCENTER)setSize(400 400)setVisible(true)

-----------------------------------------------------------------------btnexaminaraddActionListener(this)btnagregaraddActionListener(this)btnbuscaraddActionListener(this)

fin del constructor

-----------------------------------------------------------------------public void AbrirDialogo()

fileChooser=new JFileChooser()

filtrar archivos con exrensiones permitidasfileChoosersetFileFilter(filtro)int resultado=fileChoosershowOpenDialog(this)

if(resultado==JFileChooserAPPROVE_OPTION)file=fileChoosergetSelectedFile()txtfotosetText(filetoString())foto=getToolkit()getImage(txtfotogetText())foto=fotogetScaledInstance(200 20050)lblimagensetIcon(new ImageIcon(foto))

fin abrirDialogo

----------------------------------------------------------------------- metodo de la interfaz ActionListener

Overridepublic void actionPerformed(ActionEvent e)

if(egetSource()==btnexaminar)

AbrirDialogo()if(egetSource()==btnagregar)

AlumnoDao alumnoDao=new AlumnoDao()asignarDatos()mensaje= alumnoDaograbarAlumno(alumnoVO)

if (mensaje==null)cudroMensaje(Datos de alumno registrado)

elsecudroMensaje(Error +mensaje)

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1012

983120983265983143983145983150983137 983089983088 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

if(egetSource()==btnbuscar)Buscaralumno rf=new Buscaralumno()

rfshow()

fin del metodo actionPerformed

---------------------------------------------------------------------- encapsular datos en el objeto alumnoVOpublic void asignarDatos()

alumnoVO=new AlumnoVO()alumnoVOsetNombres(txtnombresgetText())alumnoVOsetApellidos(txtapellidosgetText())alumnoVOsetFoto(txtfotogetText())

fin del metodo AsignarDatos

public void cudroMensaje(String mensaje)JOptionPaneshowMessageDialog(null mensaje)

fin de la clase Presentacion

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1112

983120983265983143983145983150983137 983089983089 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

(Se utilizoacute el asistente para crear este formulario)

private void txtcodigoKeyPressed(javaawteventKeyEvent evt) if(evtgetKeyCode()==evtVK_ENTER)

Image fotoAlumnoDao a=new AlumnoDao()

try AlumnoVO alumnoVO=agetDatosAlumno(IntegerparseInt(txtcodigogetText()))

setTitle(alumnoVOgetNombres()+ +alumnoVOgetApellidos())

foto=abuscarAlumno(IntegerparseInt(txtcodigogetText()))

foto=fotogetScaledInstance(300 300ImageSCALE_DEFAULT)

lblvistaFotosetIcon(new ImageIcon(foto))

thissetLocationRelativeTo(null)

catch (SQLException ex)

catch (IOException ex)

txtcodigo

lblvistaFoto

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1212

983120983265983143983145983150983137 983089983090 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

package pecomacademiapresentacion

import javaawtBorderLayoutimport javaxswingJFrame

public class Principal extends JFramepublic Principal()

getContentPane()add(new Registraralumno () BorderLayoutCENTER)meacutetodo principal

public static void main(String []args)Principal p=new Principal()psetTitle(Alumno)psetSize(700 400)psetLocationRelativeTo(null)psetVisible(true)

fin del meacutetodo principal

Page 3: Leng Prog II Grabar y Leer Imagnes

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 312

983120983265983143983145983150983137 983091 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

4 Clase conexioacuten

package pecomacademiaconexion

import javasqlConnectionimport javasqlDriverManagerimport javasqlSQLException

public class Conexion variablesprivate Connection cn=nullprivate String us=rootprivate String clave=123private String url=jdbcmysqllocalhostacademia

-----------------------------------------------------------public Connection abrir()try

registrar driverClassforName(commysqljdbcDriver)

cn=DriverManagergetConnection(url us clave) catch (SQLException ex)

Systemoutprintf(Error en la conexion +exgetMessage())

catch (ClassNotFoundException ex) Systemoutprintf(Error al cargar driver+exgetMessage())

finallyreturn cn

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 412

983120983265983143983145983150983137 983092 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

5 Clase AlumnoVO

package pecomacademiabeanpublic class AlumnoVO

variables datos o camposprivate int idprivate String nombresprivate String apellidosprivate String foto

metodos set y get -----------------------------------------------------------------

public String getApellidos()

return apellidos

public void setApellidos(String apellidos) thisapellidos = apellidos

public String getFoto() return foto

public void setFoto(String foto)

thisfoto = foto

public int getId() return id

public void setId(int id) thisid = id

public String getNombres()

return nombres

public void setNombres(String nombres) thisnombres = nombres

fin de la clase

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 512

983120983265983143983145983150983137 983093 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

6 Clase AlumnoDao

package pecomacademiadaoimport javaawtImageimport javaioFileimport javaioFileInputStreamimport javaioIOExceptionimport javasqlimport pecomacademiabeanAlumnoVOimport pecomacademiaconexionConexion

public class AlumnoDao extends Conexion

public String grabarAlumno(AlumnoVO alumnoVO)

variablesString mensaje=nullConnection cn=nullPreparedStatement psFileInputStream fis ------------------------------------------------------------------------------ cadena sql para insertar datos a la tabla alumnoString sql = INSERT INTO alumno(nombresapellidosfoto) VALUES () abrir conexion metodo de la clase conexion esta aqui por herencia a dicha clasecn= abrir() ------------------------------------------------------------------------------try

ps = cnprepareStatement(sql)pssetString(1 alumnoVOgetNombres())pssetString(2 alumnoVOgetApellidos())

ruta puede ser cimagenesfotojpgFile filefoto = new File(alumnoVOgetFoto())

La clase FileInputStream se utiliza para leer bytes desde un archivofis = new FileInputStream(filefoto)

pssetBinaryStream(3 fisfisavailable())

psexecuteUpdate()

catch (IOException | SQLException ex) mensaje=exgetMessage()

return mensajefin del metodo grabaralumno

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 612

983120983265983143983145983150983137 983094 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

-------------------------------------------------------------------------------------------------------public Image buscarAlumno( int codigo ) throws SQLException IOException

Image rpta=nullConnection cn=nullcn=abrir()

String sql = SELECT FROM alumno where id=+codigo +

Statement stmt = cncreateStatement()ResultSet results = stmtexecuteQuery(sql)Blob imagen=nullif(resultsnext())

imagen = resultsgetBlob(foto) Esta parte es clave donde se convierte a imagenrpta= javaximageioImageIOread(imagengetBinaryStream())

return rpta

fin del meacutetodo buscarAlumno

public AlumnoVO getDatosAlumno( int codigo ) throws SQLExceptionIOException

Image rpta=nullConnection cn=nullcn=abrir()

String sql = SELECT FROM alumno where id=+codigo +

Statement stmt = cncreateStatement()ResultSet rs = stmtexecuteQuery(sql)AlumnoVO alumnoVO=nullif(rsnext())

alumnoVO=new AlumnoVO()alumnoVOsetNombres(rsgetString(nombres))alumnoVOsetApellidos(rsgetString(apellidos))

return alumnoVO

fin del meacutetodo getDatosAlumnofin de la clase AlumnoDao

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 712

983120983265983143983145983150983137 983095 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

7 Clase Registraralumno RecuperarFoto Principal

package pecomacademiapresentacionimport javaawtBorderLayoutimport javaawtColorimport javaawtImageimport javaawteventActionEvent

import javaawteventActionListenerimport javaioFileimport javaxswingimport javaxswingborderBorderimport javaxswingfilechooserFileNameExtensionFilterimport pecomacademiabeanAlumnoVOimport pecomacademiadaoAlumnoDao

public class Registraralumno extends JPanel implements ActionListener

Extension de imagenprivate FileNameExtensionFilter filtro = new FileNameExtensionFilter(Archivo de

ImagenjpgpngJPGjpgGIFgif) -------------------------------------------------------------------------------------------------------- variablesprivate String mensaje=nullprivate JPanel panel=nullprivate JLabel lblcodigoprivate JLabel lblnombresprivate JLabel lblapellidosprivate JLabel lblimagenprivate JLabel lblfotoprivate JTextField txtcodigoprivate JTextField txtnombres

private JTextField txtapellidosprivate JTextField txtfotoprivate JButton btnnuevoprivate JButton btnagregarprivate JButton btnbuscarprivate JButton btnexaminar

private File fileprivate JFileChooser fileChooserprivate Image foto

AlumnoVO alumnoVO=null

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 812

983120983265983143983145983150983137 983096 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

----------------------------------------------------------------------- constructor

public Registraralumno () panelsetLayout( new BorderLayout())panel=new JPanel()panelsetLayout(null)panelsetBackground(new Color(100 160 120))

-----------------------------------------------------------------------lblcodigo=new JLabel(Id)lblcodigosetBounds(10 40 60 20)lblnombres=new JLabel(Nombres)lblnombressetBounds(10 90 60 20)

lblapellidos=new JLabel(Apellidos)lblapellidossetBounds(10 140 60 20)lblfoto=new JLabel(Foto)lblfotosetBounds(10 190 60 20)txtcodigo=new JTextField()txtcodigosetBounds(7040 50 20)txtnombres=new JTextField()txtnombressetBounds(70 90 220 20)txtapellidos=new JTextField()txtapellidossetBounds(70 140 220 20)txtfoto=new JTextField()txtfotosetBounds(70 190 220 20)btnexaminar=new JButton(Examinar)btnexaminarsetBounds(295 190150 20)lblimagen=new JLabel()

borde a la etiqueta lblimagenBorder border=BorderFactorycreateLineBorder(Colorwhite)lblimagensetBorder(border)lblimagensetBounds(300 10 190 170)btnnuevo=new JButton(Nuevo) btnnuevosetBounds(10 240 9020)btnagregar=new JButton(Agregar) btnagregarsetBounds(100 240 9020)

btnbuscar=new JButton(Ver Foto) btnbuscarsetBounds(190 240 9020)

------------------------------------------------------------------------paneladd(lblcodigo)paneladd(lblnombres)paneladd(lblapellidos)paneladd(txtcodigo)paneladd(txtnombres)paneladd(txtapellidos)paneladd(txtfoto)

paneladd(btnnuevo)paneladd(btnagregar)

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 912

983120983265983143983145983150983137 983097 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

paneladd(btnverfoto)paneladd(btnexaminar)

paneladd(lblimagen)paneladd(lblfoto)

add(panelBorderLayoutCENTER)setSize(400 400)setVisible(true)

-----------------------------------------------------------------------btnexaminaraddActionListener(this)btnagregaraddActionListener(this)btnbuscaraddActionListener(this)

fin del constructor

-----------------------------------------------------------------------public void AbrirDialogo()

fileChooser=new JFileChooser()

filtrar archivos con exrensiones permitidasfileChoosersetFileFilter(filtro)int resultado=fileChoosershowOpenDialog(this)

if(resultado==JFileChooserAPPROVE_OPTION)file=fileChoosergetSelectedFile()txtfotosetText(filetoString())foto=getToolkit()getImage(txtfotogetText())foto=fotogetScaledInstance(200 20050)lblimagensetIcon(new ImageIcon(foto))

fin abrirDialogo

----------------------------------------------------------------------- metodo de la interfaz ActionListener

Overridepublic void actionPerformed(ActionEvent e)

if(egetSource()==btnexaminar)

AbrirDialogo()if(egetSource()==btnagregar)

AlumnoDao alumnoDao=new AlumnoDao()asignarDatos()mensaje= alumnoDaograbarAlumno(alumnoVO)

if (mensaje==null)cudroMensaje(Datos de alumno registrado)

elsecudroMensaje(Error +mensaje)

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1012

983120983265983143983145983150983137 983089983088 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

if(egetSource()==btnbuscar)Buscaralumno rf=new Buscaralumno()

rfshow()

fin del metodo actionPerformed

---------------------------------------------------------------------- encapsular datos en el objeto alumnoVOpublic void asignarDatos()

alumnoVO=new AlumnoVO()alumnoVOsetNombres(txtnombresgetText())alumnoVOsetApellidos(txtapellidosgetText())alumnoVOsetFoto(txtfotogetText())

fin del metodo AsignarDatos

public void cudroMensaje(String mensaje)JOptionPaneshowMessageDialog(null mensaje)

fin de la clase Presentacion

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1112

983120983265983143983145983150983137 983089983089 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

(Se utilizoacute el asistente para crear este formulario)

private void txtcodigoKeyPressed(javaawteventKeyEvent evt) if(evtgetKeyCode()==evtVK_ENTER)

Image fotoAlumnoDao a=new AlumnoDao()

try AlumnoVO alumnoVO=agetDatosAlumno(IntegerparseInt(txtcodigogetText()))

setTitle(alumnoVOgetNombres()+ +alumnoVOgetApellidos())

foto=abuscarAlumno(IntegerparseInt(txtcodigogetText()))

foto=fotogetScaledInstance(300 300ImageSCALE_DEFAULT)

lblvistaFotosetIcon(new ImageIcon(foto))

thissetLocationRelativeTo(null)

catch (SQLException ex)

catch (IOException ex)

txtcodigo

lblvistaFoto

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1212

983120983265983143983145983150983137 983089983090 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

package pecomacademiapresentacion

import javaawtBorderLayoutimport javaxswingJFrame

public class Principal extends JFramepublic Principal()

getContentPane()add(new Registraralumno () BorderLayoutCENTER)meacutetodo principal

public static void main(String []args)Principal p=new Principal()psetTitle(Alumno)psetSize(700 400)psetLocationRelativeTo(null)psetVisible(true)

fin del meacutetodo principal

Page 4: Leng Prog II Grabar y Leer Imagnes

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 412

983120983265983143983145983150983137 983092 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

5 Clase AlumnoVO

package pecomacademiabeanpublic class AlumnoVO

variables datos o camposprivate int idprivate String nombresprivate String apellidosprivate String foto

metodos set y get -----------------------------------------------------------------

public String getApellidos()

return apellidos

public void setApellidos(String apellidos) thisapellidos = apellidos

public String getFoto() return foto

public void setFoto(String foto)

thisfoto = foto

public int getId() return id

public void setId(int id) thisid = id

public String getNombres()

return nombres

public void setNombres(String nombres) thisnombres = nombres

fin de la clase

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 512

983120983265983143983145983150983137 983093 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

6 Clase AlumnoDao

package pecomacademiadaoimport javaawtImageimport javaioFileimport javaioFileInputStreamimport javaioIOExceptionimport javasqlimport pecomacademiabeanAlumnoVOimport pecomacademiaconexionConexion

public class AlumnoDao extends Conexion

public String grabarAlumno(AlumnoVO alumnoVO)

variablesString mensaje=nullConnection cn=nullPreparedStatement psFileInputStream fis ------------------------------------------------------------------------------ cadena sql para insertar datos a la tabla alumnoString sql = INSERT INTO alumno(nombresapellidosfoto) VALUES () abrir conexion metodo de la clase conexion esta aqui por herencia a dicha clasecn= abrir() ------------------------------------------------------------------------------try

ps = cnprepareStatement(sql)pssetString(1 alumnoVOgetNombres())pssetString(2 alumnoVOgetApellidos())

ruta puede ser cimagenesfotojpgFile filefoto = new File(alumnoVOgetFoto())

La clase FileInputStream se utiliza para leer bytes desde un archivofis = new FileInputStream(filefoto)

pssetBinaryStream(3 fisfisavailable())

psexecuteUpdate()

catch (IOException | SQLException ex) mensaje=exgetMessage()

return mensajefin del metodo grabaralumno

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 612

983120983265983143983145983150983137 983094 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

-------------------------------------------------------------------------------------------------------public Image buscarAlumno( int codigo ) throws SQLException IOException

Image rpta=nullConnection cn=nullcn=abrir()

String sql = SELECT FROM alumno where id=+codigo +

Statement stmt = cncreateStatement()ResultSet results = stmtexecuteQuery(sql)Blob imagen=nullif(resultsnext())

imagen = resultsgetBlob(foto) Esta parte es clave donde se convierte a imagenrpta= javaximageioImageIOread(imagengetBinaryStream())

return rpta

fin del meacutetodo buscarAlumno

public AlumnoVO getDatosAlumno( int codigo ) throws SQLExceptionIOException

Image rpta=nullConnection cn=nullcn=abrir()

String sql = SELECT FROM alumno where id=+codigo +

Statement stmt = cncreateStatement()ResultSet rs = stmtexecuteQuery(sql)AlumnoVO alumnoVO=nullif(rsnext())

alumnoVO=new AlumnoVO()alumnoVOsetNombres(rsgetString(nombres))alumnoVOsetApellidos(rsgetString(apellidos))

return alumnoVO

fin del meacutetodo getDatosAlumnofin de la clase AlumnoDao

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 712

983120983265983143983145983150983137 983095 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

7 Clase Registraralumno RecuperarFoto Principal

package pecomacademiapresentacionimport javaawtBorderLayoutimport javaawtColorimport javaawtImageimport javaawteventActionEvent

import javaawteventActionListenerimport javaioFileimport javaxswingimport javaxswingborderBorderimport javaxswingfilechooserFileNameExtensionFilterimport pecomacademiabeanAlumnoVOimport pecomacademiadaoAlumnoDao

public class Registraralumno extends JPanel implements ActionListener

Extension de imagenprivate FileNameExtensionFilter filtro = new FileNameExtensionFilter(Archivo de

ImagenjpgpngJPGjpgGIFgif) -------------------------------------------------------------------------------------------------------- variablesprivate String mensaje=nullprivate JPanel panel=nullprivate JLabel lblcodigoprivate JLabel lblnombresprivate JLabel lblapellidosprivate JLabel lblimagenprivate JLabel lblfotoprivate JTextField txtcodigoprivate JTextField txtnombres

private JTextField txtapellidosprivate JTextField txtfotoprivate JButton btnnuevoprivate JButton btnagregarprivate JButton btnbuscarprivate JButton btnexaminar

private File fileprivate JFileChooser fileChooserprivate Image foto

AlumnoVO alumnoVO=null

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 812

983120983265983143983145983150983137 983096 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

----------------------------------------------------------------------- constructor

public Registraralumno () panelsetLayout( new BorderLayout())panel=new JPanel()panelsetLayout(null)panelsetBackground(new Color(100 160 120))

-----------------------------------------------------------------------lblcodigo=new JLabel(Id)lblcodigosetBounds(10 40 60 20)lblnombres=new JLabel(Nombres)lblnombressetBounds(10 90 60 20)

lblapellidos=new JLabel(Apellidos)lblapellidossetBounds(10 140 60 20)lblfoto=new JLabel(Foto)lblfotosetBounds(10 190 60 20)txtcodigo=new JTextField()txtcodigosetBounds(7040 50 20)txtnombres=new JTextField()txtnombressetBounds(70 90 220 20)txtapellidos=new JTextField()txtapellidossetBounds(70 140 220 20)txtfoto=new JTextField()txtfotosetBounds(70 190 220 20)btnexaminar=new JButton(Examinar)btnexaminarsetBounds(295 190150 20)lblimagen=new JLabel()

borde a la etiqueta lblimagenBorder border=BorderFactorycreateLineBorder(Colorwhite)lblimagensetBorder(border)lblimagensetBounds(300 10 190 170)btnnuevo=new JButton(Nuevo) btnnuevosetBounds(10 240 9020)btnagregar=new JButton(Agregar) btnagregarsetBounds(100 240 9020)

btnbuscar=new JButton(Ver Foto) btnbuscarsetBounds(190 240 9020)

------------------------------------------------------------------------paneladd(lblcodigo)paneladd(lblnombres)paneladd(lblapellidos)paneladd(txtcodigo)paneladd(txtnombres)paneladd(txtapellidos)paneladd(txtfoto)

paneladd(btnnuevo)paneladd(btnagregar)

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 912

983120983265983143983145983150983137 983097 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

paneladd(btnverfoto)paneladd(btnexaminar)

paneladd(lblimagen)paneladd(lblfoto)

add(panelBorderLayoutCENTER)setSize(400 400)setVisible(true)

-----------------------------------------------------------------------btnexaminaraddActionListener(this)btnagregaraddActionListener(this)btnbuscaraddActionListener(this)

fin del constructor

-----------------------------------------------------------------------public void AbrirDialogo()

fileChooser=new JFileChooser()

filtrar archivos con exrensiones permitidasfileChoosersetFileFilter(filtro)int resultado=fileChoosershowOpenDialog(this)

if(resultado==JFileChooserAPPROVE_OPTION)file=fileChoosergetSelectedFile()txtfotosetText(filetoString())foto=getToolkit()getImage(txtfotogetText())foto=fotogetScaledInstance(200 20050)lblimagensetIcon(new ImageIcon(foto))

fin abrirDialogo

----------------------------------------------------------------------- metodo de la interfaz ActionListener

Overridepublic void actionPerformed(ActionEvent e)

if(egetSource()==btnexaminar)

AbrirDialogo()if(egetSource()==btnagregar)

AlumnoDao alumnoDao=new AlumnoDao()asignarDatos()mensaje= alumnoDaograbarAlumno(alumnoVO)

if (mensaje==null)cudroMensaje(Datos de alumno registrado)

elsecudroMensaje(Error +mensaje)

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1012

983120983265983143983145983150983137 983089983088 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

if(egetSource()==btnbuscar)Buscaralumno rf=new Buscaralumno()

rfshow()

fin del metodo actionPerformed

---------------------------------------------------------------------- encapsular datos en el objeto alumnoVOpublic void asignarDatos()

alumnoVO=new AlumnoVO()alumnoVOsetNombres(txtnombresgetText())alumnoVOsetApellidos(txtapellidosgetText())alumnoVOsetFoto(txtfotogetText())

fin del metodo AsignarDatos

public void cudroMensaje(String mensaje)JOptionPaneshowMessageDialog(null mensaje)

fin de la clase Presentacion

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1112

983120983265983143983145983150983137 983089983089 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

(Se utilizoacute el asistente para crear este formulario)

private void txtcodigoKeyPressed(javaawteventKeyEvent evt) if(evtgetKeyCode()==evtVK_ENTER)

Image fotoAlumnoDao a=new AlumnoDao()

try AlumnoVO alumnoVO=agetDatosAlumno(IntegerparseInt(txtcodigogetText()))

setTitle(alumnoVOgetNombres()+ +alumnoVOgetApellidos())

foto=abuscarAlumno(IntegerparseInt(txtcodigogetText()))

foto=fotogetScaledInstance(300 300ImageSCALE_DEFAULT)

lblvistaFotosetIcon(new ImageIcon(foto))

thissetLocationRelativeTo(null)

catch (SQLException ex)

catch (IOException ex)

txtcodigo

lblvistaFoto

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1212

983120983265983143983145983150983137 983089983090 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

package pecomacademiapresentacion

import javaawtBorderLayoutimport javaxswingJFrame

public class Principal extends JFramepublic Principal()

getContentPane()add(new Registraralumno () BorderLayoutCENTER)meacutetodo principal

public static void main(String []args)Principal p=new Principal()psetTitle(Alumno)psetSize(700 400)psetLocationRelativeTo(null)psetVisible(true)

fin del meacutetodo principal

Page 5: Leng Prog II Grabar y Leer Imagnes

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 512

983120983265983143983145983150983137 983093 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

6 Clase AlumnoDao

package pecomacademiadaoimport javaawtImageimport javaioFileimport javaioFileInputStreamimport javaioIOExceptionimport javasqlimport pecomacademiabeanAlumnoVOimport pecomacademiaconexionConexion

public class AlumnoDao extends Conexion

public String grabarAlumno(AlumnoVO alumnoVO)

variablesString mensaje=nullConnection cn=nullPreparedStatement psFileInputStream fis ------------------------------------------------------------------------------ cadena sql para insertar datos a la tabla alumnoString sql = INSERT INTO alumno(nombresapellidosfoto) VALUES () abrir conexion metodo de la clase conexion esta aqui por herencia a dicha clasecn= abrir() ------------------------------------------------------------------------------try

ps = cnprepareStatement(sql)pssetString(1 alumnoVOgetNombres())pssetString(2 alumnoVOgetApellidos())

ruta puede ser cimagenesfotojpgFile filefoto = new File(alumnoVOgetFoto())

La clase FileInputStream se utiliza para leer bytes desde un archivofis = new FileInputStream(filefoto)

pssetBinaryStream(3 fisfisavailable())

psexecuteUpdate()

catch (IOException | SQLException ex) mensaje=exgetMessage()

return mensajefin del metodo grabaralumno

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 612

983120983265983143983145983150983137 983094 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

-------------------------------------------------------------------------------------------------------public Image buscarAlumno( int codigo ) throws SQLException IOException

Image rpta=nullConnection cn=nullcn=abrir()

String sql = SELECT FROM alumno where id=+codigo +

Statement stmt = cncreateStatement()ResultSet results = stmtexecuteQuery(sql)Blob imagen=nullif(resultsnext())

imagen = resultsgetBlob(foto) Esta parte es clave donde se convierte a imagenrpta= javaximageioImageIOread(imagengetBinaryStream())

return rpta

fin del meacutetodo buscarAlumno

public AlumnoVO getDatosAlumno( int codigo ) throws SQLExceptionIOException

Image rpta=nullConnection cn=nullcn=abrir()

String sql = SELECT FROM alumno where id=+codigo +

Statement stmt = cncreateStatement()ResultSet rs = stmtexecuteQuery(sql)AlumnoVO alumnoVO=nullif(rsnext())

alumnoVO=new AlumnoVO()alumnoVOsetNombres(rsgetString(nombres))alumnoVOsetApellidos(rsgetString(apellidos))

return alumnoVO

fin del meacutetodo getDatosAlumnofin de la clase AlumnoDao

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 712

983120983265983143983145983150983137 983095 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

7 Clase Registraralumno RecuperarFoto Principal

package pecomacademiapresentacionimport javaawtBorderLayoutimport javaawtColorimport javaawtImageimport javaawteventActionEvent

import javaawteventActionListenerimport javaioFileimport javaxswingimport javaxswingborderBorderimport javaxswingfilechooserFileNameExtensionFilterimport pecomacademiabeanAlumnoVOimport pecomacademiadaoAlumnoDao

public class Registraralumno extends JPanel implements ActionListener

Extension de imagenprivate FileNameExtensionFilter filtro = new FileNameExtensionFilter(Archivo de

ImagenjpgpngJPGjpgGIFgif) -------------------------------------------------------------------------------------------------------- variablesprivate String mensaje=nullprivate JPanel panel=nullprivate JLabel lblcodigoprivate JLabel lblnombresprivate JLabel lblapellidosprivate JLabel lblimagenprivate JLabel lblfotoprivate JTextField txtcodigoprivate JTextField txtnombres

private JTextField txtapellidosprivate JTextField txtfotoprivate JButton btnnuevoprivate JButton btnagregarprivate JButton btnbuscarprivate JButton btnexaminar

private File fileprivate JFileChooser fileChooserprivate Image foto

AlumnoVO alumnoVO=null

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 812

983120983265983143983145983150983137 983096 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

----------------------------------------------------------------------- constructor

public Registraralumno () panelsetLayout( new BorderLayout())panel=new JPanel()panelsetLayout(null)panelsetBackground(new Color(100 160 120))

-----------------------------------------------------------------------lblcodigo=new JLabel(Id)lblcodigosetBounds(10 40 60 20)lblnombres=new JLabel(Nombres)lblnombressetBounds(10 90 60 20)

lblapellidos=new JLabel(Apellidos)lblapellidossetBounds(10 140 60 20)lblfoto=new JLabel(Foto)lblfotosetBounds(10 190 60 20)txtcodigo=new JTextField()txtcodigosetBounds(7040 50 20)txtnombres=new JTextField()txtnombressetBounds(70 90 220 20)txtapellidos=new JTextField()txtapellidossetBounds(70 140 220 20)txtfoto=new JTextField()txtfotosetBounds(70 190 220 20)btnexaminar=new JButton(Examinar)btnexaminarsetBounds(295 190150 20)lblimagen=new JLabel()

borde a la etiqueta lblimagenBorder border=BorderFactorycreateLineBorder(Colorwhite)lblimagensetBorder(border)lblimagensetBounds(300 10 190 170)btnnuevo=new JButton(Nuevo) btnnuevosetBounds(10 240 9020)btnagregar=new JButton(Agregar) btnagregarsetBounds(100 240 9020)

btnbuscar=new JButton(Ver Foto) btnbuscarsetBounds(190 240 9020)

------------------------------------------------------------------------paneladd(lblcodigo)paneladd(lblnombres)paneladd(lblapellidos)paneladd(txtcodigo)paneladd(txtnombres)paneladd(txtapellidos)paneladd(txtfoto)

paneladd(btnnuevo)paneladd(btnagregar)

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 912

983120983265983143983145983150983137 983097 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

paneladd(btnverfoto)paneladd(btnexaminar)

paneladd(lblimagen)paneladd(lblfoto)

add(panelBorderLayoutCENTER)setSize(400 400)setVisible(true)

-----------------------------------------------------------------------btnexaminaraddActionListener(this)btnagregaraddActionListener(this)btnbuscaraddActionListener(this)

fin del constructor

-----------------------------------------------------------------------public void AbrirDialogo()

fileChooser=new JFileChooser()

filtrar archivos con exrensiones permitidasfileChoosersetFileFilter(filtro)int resultado=fileChoosershowOpenDialog(this)

if(resultado==JFileChooserAPPROVE_OPTION)file=fileChoosergetSelectedFile()txtfotosetText(filetoString())foto=getToolkit()getImage(txtfotogetText())foto=fotogetScaledInstance(200 20050)lblimagensetIcon(new ImageIcon(foto))

fin abrirDialogo

----------------------------------------------------------------------- metodo de la interfaz ActionListener

Overridepublic void actionPerformed(ActionEvent e)

if(egetSource()==btnexaminar)

AbrirDialogo()if(egetSource()==btnagregar)

AlumnoDao alumnoDao=new AlumnoDao()asignarDatos()mensaje= alumnoDaograbarAlumno(alumnoVO)

if (mensaje==null)cudroMensaje(Datos de alumno registrado)

elsecudroMensaje(Error +mensaje)

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1012

983120983265983143983145983150983137 983089983088 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

if(egetSource()==btnbuscar)Buscaralumno rf=new Buscaralumno()

rfshow()

fin del metodo actionPerformed

---------------------------------------------------------------------- encapsular datos en el objeto alumnoVOpublic void asignarDatos()

alumnoVO=new AlumnoVO()alumnoVOsetNombres(txtnombresgetText())alumnoVOsetApellidos(txtapellidosgetText())alumnoVOsetFoto(txtfotogetText())

fin del metodo AsignarDatos

public void cudroMensaje(String mensaje)JOptionPaneshowMessageDialog(null mensaje)

fin de la clase Presentacion

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1112

983120983265983143983145983150983137 983089983089 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

(Se utilizoacute el asistente para crear este formulario)

private void txtcodigoKeyPressed(javaawteventKeyEvent evt) if(evtgetKeyCode()==evtVK_ENTER)

Image fotoAlumnoDao a=new AlumnoDao()

try AlumnoVO alumnoVO=agetDatosAlumno(IntegerparseInt(txtcodigogetText()))

setTitle(alumnoVOgetNombres()+ +alumnoVOgetApellidos())

foto=abuscarAlumno(IntegerparseInt(txtcodigogetText()))

foto=fotogetScaledInstance(300 300ImageSCALE_DEFAULT)

lblvistaFotosetIcon(new ImageIcon(foto))

thissetLocationRelativeTo(null)

catch (SQLException ex)

catch (IOException ex)

txtcodigo

lblvistaFoto

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1212

983120983265983143983145983150983137 983089983090 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

package pecomacademiapresentacion

import javaawtBorderLayoutimport javaxswingJFrame

public class Principal extends JFramepublic Principal()

getContentPane()add(new Registraralumno () BorderLayoutCENTER)meacutetodo principal

public static void main(String []args)Principal p=new Principal()psetTitle(Alumno)psetSize(700 400)psetLocationRelativeTo(null)psetVisible(true)

fin del meacutetodo principal

Page 6: Leng Prog II Grabar y Leer Imagnes

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 612

983120983265983143983145983150983137 983094 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

-------------------------------------------------------------------------------------------------------public Image buscarAlumno( int codigo ) throws SQLException IOException

Image rpta=nullConnection cn=nullcn=abrir()

String sql = SELECT FROM alumno where id=+codigo +

Statement stmt = cncreateStatement()ResultSet results = stmtexecuteQuery(sql)Blob imagen=nullif(resultsnext())

imagen = resultsgetBlob(foto) Esta parte es clave donde se convierte a imagenrpta= javaximageioImageIOread(imagengetBinaryStream())

return rpta

fin del meacutetodo buscarAlumno

public AlumnoVO getDatosAlumno( int codigo ) throws SQLExceptionIOException

Image rpta=nullConnection cn=nullcn=abrir()

String sql = SELECT FROM alumno where id=+codigo +

Statement stmt = cncreateStatement()ResultSet rs = stmtexecuteQuery(sql)AlumnoVO alumnoVO=nullif(rsnext())

alumnoVO=new AlumnoVO()alumnoVOsetNombres(rsgetString(nombres))alumnoVOsetApellidos(rsgetString(apellidos))

return alumnoVO

fin del meacutetodo getDatosAlumnofin de la clase AlumnoDao

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 712

983120983265983143983145983150983137 983095 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

7 Clase Registraralumno RecuperarFoto Principal

package pecomacademiapresentacionimport javaawtBorderLayoutimport javaawtColorimport javaawtImageimport javaawteventActionEvent

import javaawteventActionListenerimport javaioFileimport javaxswingimport javaxswingborderBorderimport javaxswingfilechooserFileNameExtensionFilterimport pecomacademiabeanAlumnoVOimport pecomacademiadaoAlumnoDao

public class Registraralumno extends JPanel implements ActionListener

Extension de imagenprivate FileNameExtensionFilter filtro = new FileNameExtensionFilter(Archivo de

ImagenjpgpngJPGjpgGIFgif) -------------------------------------------------------------------------------------------------------- variablesprivate String mensaje=nullprivate JPanel panel=nullprivate JLabel lblcodigoprivate JLabel lblnombresprivate JLabel lblapellidosprivate JLabel lblimagenprivate JLabel lblfotoprivate JTextField txtcodigoprivate JTextField txtnombres

private JTextField txtapellidosprivate JTextField txtfotoprivate JButton btnnuevoprivate JButton btnagregarprivate JButton btnbuscarprivate JButton btnexaminar

private File fileprivate JFileChooser fileChooserprivate Image foto

AlumnoVO alumnoVO=null

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 812

983120983265983143983145983150983137 983096 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

----------------------------------------------------------------------- constructor

public Registraralumno () panelsetLayout( new BorderLayout())panel=new JPanel()panelsetLayout(null)panelsetBackground(new Color(100 160 120))

-----------------------------------------------------------------------lblcodigo=new JLabel(Id)lblcodigosetBounds(10 40 60 20)lblnombres=new JLabel(Nombres)lblnombressetBounds(10 90 60 20)

lblapellidos=new JLabel(Apellidos)lblapellidossetBounds(10 140 60 20)lblfoto=new JLabel(Foto)lblfotosetBounds(10 190 60 20)txtcodigo=new JTextField()txtcodigosetBounds(7040 50 20)txtnombres=new JTextField()txtnombressetBounds(70 90 220 20)txtapellidos=new JTextField()txtapellidossetBounds(70 140 220 20)txtfoto=new JTextField()txtfotosetBounds(70 190 220 20)btnexaminar=new JButton(Examinar)btnexaminarsetBounds(295 190150 20)lblimagen=new JLabel()

borde a la etiqueta lblimagenBorder border=BorderFactorycreateLineBorder(Colorwhite)lblimagensetBorder(border)lblimagensetBounds(300 10 190 170)btnnuevo=new JButton(Nuevo) btnnuevosetBounds(10 240 9020)btnagregar=new JButton(Agregar) btnagregarsetBounds(100 240 9020)

btnbuscar=new JButton(Ver Foto) btnbuscarsetBounds(190 240 9020)

------------------------------------------------------------------------paneladd(lblcodigo)paneladd(lblnombres)paneladd(lblapellidos)paneladd(txtcodigo)paneladd(txtnombres)paneladd(txtapellidos)paneladd(txtfoto)

paneladd(btnnuevo)paneladd(btnagregar)

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 912

983120983265983143983145983150983137 983097 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

paneladd(btnverfoto)paneladd(btnexaminar)

paneladd(lblimagen)paneladd(lblfoto)

add(panelBorderLayoutCENTER)setSize(400 400)setVisible(true)

-----------------------------------------------------------------------btnexaminaraddActionListener(this)btnagregaraddActionListener(this)btnbuscaraddActionListener(this)

fin del constructor

-----------------------------------------------------------------------public void AbrirDialogo()

fileChooser=new JFileChooser()

filtrar archivos con exrensiones permitidasfileChoosersetFileFilter(filtro)int resultado=fileChoosershowOpenDialog(this)

if(resultado==JFileChooserAPPROVE_OPTION)file=fileChoosergetSelectedFile()txtfotosetText(filetoString())foto=getToolkit()getImage(txtfotogetText())foto=fotogetScaledInstance(200 20050)lblimagensetIcon(new ImageIcon(foto))

fin abrirDialogo

----------------------------------------------------------------------- metodo de la interfaz ActionListener

Overridepublic void actionPerformed(ActionEvent e)

if(egetSource()==btnexaminar)

AbrirDialogo()if(egetSource()==btnagregar)

AlumnoDao alumnoDao=new AlumnoDao()asignarDatos()mensaje= alumnoDaograbarAlumno(alumnoVO)

if (mensaje==null)cudroMensaje(Datos de alumno registrado)

elsecudroMensaje(Error +mensaje)

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1012

983120983265983143983145983150983137 983089983088 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

if(egetSource()==btnbuscar)Buscaralumno rf=new Buscaralumno()

rfshow()

fin del metodo actionPerformed

---------------------------------------------------------------------- encapsular datos en el objeto alumnoVOpublic void asignarDatos()

alumnoVO=new AlumnoVO()alumnoVOsetNombres(txtnombresgetText())alumnoVOsetApellidos(txtapellidosgetText())alumnoVOsetFoto(txtfotogetText())

fin del metodo AsignarDatos

public void cudroMensaje(String mensaje)JOptionPaneshowMessageDialog(null mensaje)

fin de la clase Presentacion

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1112

983120983265983143983145983150983137 983089983089 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

(Se utilizoacute el asistente para crear este formulario)

private void txtcodigoKeyPressed(javaawteventKeyEvent evt) if(evtgetKeyCode()==evtVK_ENTER)

Image fotoAlumnoDao a=new AlumnoDao()

try AlumnoVO alumnoVO=agetDatosAlumno(IntegerparseInt(txtcodigogetText()))

setTitle(alumnoVOgetNombres()+ +alumnoVOgetApellidos())

foto=abuscarAlumno(IntegerparseInt(txtcodigogetText()))

foto=fotogetScaledInstance(300 300ImageSCALE_DEFAULT)

lblvistaFotosetIcon(new ImageIcon(foto))

thissetLocationRelativeTo(null)

catch (SQLException ex)

catch (IOException ex)

txtcodigo

lblvistaFoto

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1212

983120983265983143983145983150983137 983089983090 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

package pecomacademiapresentacion

import javaawtBorderLayoutimport javaxswingJFrame

public class Principal extends JFramepublic Principal()

getContentPane()add(new Registraralumno () BorderLayoutCENTER)meacutetodo principal

public static void main(String []args)Principal p=new Principal()psetTitle(Alumno)psetSize(700 400)psetLocationRelativeTo(null)psetVisible(true)

fin del meacutetodo principal

Page 7: Leng Prog II Grabar y Leer Imagnes

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 712

983120983265983143983145983150983137 983095 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

7 Clase Registraralumno RecuperarFoto Principal

package pecomacademiapresentacionimport javaawtBorderLayoutimport javaawtColorimport javaawtImageimport javaawteventActionEvent

import javaawteventActionListenerimport javaioFileimport javaxswingimport javaxswingborderBorderimport javaxswingfilechooserFileNameExtensionFilterimport pecomacademiabeanAlumnoVOimport pecomacademiadaoAlumnoDao

public class Registraralumno extends JPanel implements ActionListener

Extension de imagenprivate FileNameExtensionFilter filtro = new FileNameExtensionFilter(Archivo de

ImagenjpgpngJPGjpgGIFgif) -------------------------------------------------------------------------------------------------------- variablesprivate String mensaje=nullprivate JPanel panel=nullprivate JLabel lblcodigoprivate JLabel lblnombresprivate JLabel lblapellidosprivate JLabel lblimagenprivate JLabel lblfotoprivate JTextField txtcodigoprivate JTextField txtnombres

private JTextField txtapellidosprivate JTextField txtfotoprivate JButton btnnuevoprivate JButton btnagregarprivate JButton btnbuscarprivate JButton btnexaminar

private File fileprivate JFileChooser fileChooserprivate Image foto

AlumnoVO alumnoVO=null

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 812

983120983265983143983145983150983137 983096 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

----------------------------------------------------------------------- constructor

public Registraralumno () panelsetLayout( new BorderLayout())panel=new JPanel()panelsetLayout(null)panelsetBackground(new Color(100 160 120))

-----------------------------------------------------------------------lblcodigo=new JLabel(Id)lblcodigosetBounds(10 40 60 20)lblnombres=new JLabel(Nombres)lblnombressetBounds(10 90 60 20)

lblapellidos=new JLabel(Apellidos)lblapellidossetBounds(10 140 60 20)lblfoto=new JLabel(Foto)lblfotosetBounds(10 190 60 20)txtcodigo=new JTextField()txtcodigosetBounds(7040 50 20)txtnombres=new JTextField()txtnombressetBounds(70 90 220 20)txtapellidos=new JTextField()txtapellidossetBounds(70 140 220 20)txtfoto=new JTextField()txtfotosetBounds(70 190 220 20)btnexaminar=new JButton(Examinar)btnexaminarsetBounds(295 190150 20)lblimagen=new JLabel()

borde a la etiqueta lblimagenBorder border=BorderFactorycreateLineBorder(Colorwhite)lblimagensetBorder(border)lblimagensetBounds(300 10 190 170)btnnuevo=new JButton(Nuevo) btnnuevosetBounds(10 240 9020)btnagregar=new JButton(Agregar) btnagregarsetBounds(100 240 9020)

btnbuscar=new JButton(Ver Foto) btnbuscarsetBounds(190 240 9020)

------------------------------------------------------------------------paneladd(lblcodigo)paneladd(lblnombres)paneladd(lblapellidos)paneladd(txtcodigo)paneladd(txtnombres)paneladd(txtapellidos)paneladd(txtfoto)

paneladd(btnnuevo)paneladd(btnagregar)

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 912

983120983265983143983145983150983137 983097 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

paneladd(btnverfoto)paneladd(btnexaminar)

paneladd(lblimagen)paneladd(lblfoto)

add(panelBorderLayoutCENTER)setSize(400 400)setVisible(true)

-----------------------------------------------------------------------btnexaminaraddActionListener(this)btnagregaraddActionListener(this)btnbuscaraddActionListener(this)

fin del constructor

-----------------------------------------------------------------------public void AbrirDialogo()

fileChooser=new JFileChooser()

filtrar archivos con exrensiones permitidasfileChoosersetFileFilter(filtro)int resultado=fileChoosershowOpenDialog(this)

if(resultado==JFileChooserAPPROVE_OPTION)file=fileChoosergetSelectedFile()txtfotosetText(filetoString())foto=getToolkit()getImage(txtfotogetText())foto=fotogetScaledInstance(200 20050)lblimagensetIcon(new ImageIcon(foto))

fin abrirDialogo

----------------------------------------------------------------------- metodo de la interfaz ActionListener

Overridepublic void actionPerformed(ActionEvent e)

if(egetSource()==btnexaminar)

AbrirDialogo()if(egetSource()==btnagregar)

AlumnoDao alumnoDao=new AlumnoDao()asignarDatos()mensaje= alumnoDaograbarAlumno(alumnoVO)

if (mensaje==null)cudroMensaje(Datos de alumno registrado)

elsecudroMensaje(Error +mensaje)

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1012

983120983265983143983145983150983137 983089983088 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

if(egetSource()==btnbuscar)Buscaralumno rf=new Buscaralumno()

rfshow()

fin del metodo actionPerformed

---------------------------------------------------------------------- encapsular datos en el objeto alumnoVOpublic void asignarDatos()

alumnoVO=new AlumnoVO()alumnoVOsetNombres(txtnombresgetText())alumnoVOsetApellidos(txtapellidosgetText())alumnoVOsetFoto(txtfotogetText())

fin del metodo AsignarDatos

public void cudroMensaje(String mensaje)JOptionPaneshowMessageDialog(null mensaje)

fin de la clase Presentacion

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1112

983120983265983143983145983150983137 983089983089 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

(Se utilizoacute el asistente para crear este formulario)

private void txtcodigoKeyPressed(javaawteventKeyEvent evt) if(evtgetKeyCode()==evtVK_ENTER)

Image fotoAlumnoDao a=new AlumnoDao()

try AlumnoVO alumnoVO=agetDatosAlumno(IntegerparseInt(txtcodigogetText()))

setTitle(alumnoVOgetNombres()+ +alumnoVOgetApellidos())

foto=abuscarAlumno(IntegerparseInt(txtcodigogetText()))

foto=fotogetScaledInstance(300 300ImageSCALE_DEFAULT)

lblvistaFotosetIcon(new ImageIcon(foto))

thissetLocationRelativeTo(null)

catch (SQLException ex)

catch (IOException ex)

txtcodigo

lblvistaFoto

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1212

983120983265983143983145983150983137 983089983090 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

package pecomacademiapresentacion

import javaawtBorderLayoutimport javaxswingJFrame

public class Principal extends JFramepublic Principal()

getContentPane()add(new Registraralumno () BorderLayoutCENTER)meacutetodo principal

public static void main(String []args)Principal p=new Principal()psetTitle(Alumno)psetSize(700 400)psetLocationRelativeTo(null)psetVisible(true)

fin del meacutetodo principal

Page 8: Leng Prog II Grabar y Leer Imagnes

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 812

983120983265983143983145983150983137 983096 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

----------------------------------------------------------------------- constructor

public Registraralumno () panelsetLayout( new BorderLayout())panel=new JPanel()panelsetLayout(null)panelsetBackground(new Color(100 160 120))

-----------------------------------------------------------------------lblcodigo=new JLabel(Id)lblcodigosetBounds(10 40 60 20)lblnombres=new JLabel(Nombres)lblnombressetBounds(10 90 60 20)

lblapellidos=new JLabel(Apellidos)lblapellidossetBounds(10 140 60 20)lblfoto=new JLabel(Foto)lblfotosetBounds(10 190 60 20)txtcodigo=new JTextField()txtcodigosetBounds(7040 50 20)txtnombres=new JTextField()txtnombressetBounds(70 90 220 20)txtapellidos=new JTextField()txtapellidossetBounds(70 140 220 20)txtfoto=new JTextField()txtfotosetBounds(70 190 220 20)btnexaminar=new JButton(Examinar)btnexaminarsetBounds(295 190150 20)lblimagen=new JLabel()

borde a la etiqueta lblimagenBorder border=BorderFactorycreateLineBorder(Colorwhite)lblimagensetBorder(border)lblimagensetBounds(300 10 190 170)btnnuevo=new JButton(Nuevo) btnnuevosetBounds(10 240 9020)btnagregar=new JButton(Agregar) btnagregarsetBounds(100 240 9020)

btnbuscar=new JButton(Ver Foto) btnbuscarsetBounds(190 240 9020)

------------------------------------------------------------------------paneladd(lblcodigo)paneladd(lblnombres)paneladd(lblapellidos)paneladd(txtcodigo)paneladd(txtnombres)paneladd(txtapellidos)paneladd(txtfoto)

paneladd(btnnuevo)paneladd(btnagregar)

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 912

983120983265983143983145983150983137 983097 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

paneladd(btnverfoto)paneladd(btnexaminar)

paneladd(lblimagen)paneladd(lblfoto)

add(panelBorderLayoutCENTER)setSize(400 400)setVisible(true)

-----------------------------------------------------------------------btnexaminaraddActionListener(this)btnagregaraddActionListener(this)btnbuscaraddActionListener(this)

fin del constructor

-----------------------------------------------------------------------public void AbrirDialogo()

fileChooser=new JFileChooser()

filtrar archivos con exrensiones permitidasfileChoosersetFileFilter(filtro)int resultado=fileChoosershowOpenDialog(this)

if(resultado==JFileChooserAPPROVE_OPTION)file=fileChoosergetSelectedFile()txtfotosetText(filetoString())foto=getToolkit()getImage(txtfotogetText())foto=fotogetScaledInstance(200 20050)lblimagensetIcon(new ImageIcon(foto))

fin abrirDialogo

----------------------------------------------------------------------- metodo de la interfaz ActionListener

Overridepublic void actionPerformed(ActionEvent e)

if(egetSource()==btnexaminar)

AbrirDialogo()if(egetSource()==btnagregar)

AlumnoDao alumnoDao=new AlumnoDao()asignarDatos()mensaje= alumnoDaograbarAlumno(alumnoVO)

if (mensaje==null)cudroMensaje(Datos de alumno registrado)

elsecudroMensaje(Error +mensaje)

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1012

983120983265983143983145983150983137 983089983088 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

if(egetSource()==btnbuscar)Buscaralumno rf=new Buscaralumno()

rfshow()

fin del metodo actionPerformed

---------------------------------------------------------------------- encapsular datos en el objeto alumnoVOpublic void asignarDatos()

alumnoVO=new AlumnoVO()alumnoVOsetNombres(txtnombresgetText())alumnoVOsetApellidos(txtapellidosgetText())alumnoVOsetFoto(txtfotogetText())

fin del metodo AsignarDatos

public void cudroMensaje(String mensaje)JOptionPaneshowMessageDialog(null mensaje)

fin de la clase Presentacion

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1112

983120983265983143983145983150983137 983089983089 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

(Se utilizoacute el asistente para crear este formulario)

private void txtcodigoKeyPressed(javaawteventKeyEvent evt) if(evtgetKeyCode()==evtVK_ENTER)

Image fotoAlumnoDao a=new AlumnoDao()

try AlumnoVO alumnoVO=agetDatosAlumno(IntegerparseInt(txtcodigogetText()))

setTitle(alumnoVOgetNombres()+ +alumnoVOgetApellidos())

foto=abuscarAlumno(IntegerparseInt(txtcodigogetText()))

foto=fotogetScaledInstance(300 300ImageSCALE_DEFAULT)

lblvistaFotosetIcon(new ImageIcon(foto))

thissetLocationRelativeTo(null)

catch (SQLException ex)

catch (IOException ex)

txtcodigo

lblvistaFoto

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1212

983120983265983143983145983150983137 983089983090 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

package pecomacademiapresentacion

import javaawtBorderLayoutimport javaxswingJFrame

public class Principal extends JFramepublic Principal()

getContentPane()add(new Registraralumno () BorderLayoutCENTER)meacutetodo principal

public static void main(String []args)Principal p=new Principal()psetTitle(Alumno)psetSize(700 400)psetLocationRelativeTo(null)psetVisible(true)

fin del meacutetodo principal

Page 9: Leng Prog II Grabar y Leer Imagnes

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 912

983120983265983143983145983150983137 983097 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

paneladd(btnverfoto)paneladd(btnexaminar)

paneladd(lblimagen)paneladd(lblfoto)

add(panelBorderLayoutCENTER)setSize(400 400)setVisible(true)

-----------------------------------------------------------------------btnexaminaraddActionListener(this)btnagregaraddActionListener(this)btnbuscaraddActionListener(this)

fin del constructor

-----------------------------------------------------------------------public void AbrirDialogo()

fileChooser=new JFileChooser()

filtrar archivos con exrensiones permitidasfileChoosersetFileFilter(filtro)int resultado=fileChoosershowOpenDialog(this)

if(resultado==JFileChooserAPPROVE_OPTION)file=fileChoosergetSelectedFile()txtfotosetText(filetoString())foto=getToolkit()getImage(txtfotogetText())foto=fotogetScaledInstance(200 20050)lblimagensetIcon(new ImageIcon(foto))

fin abrirDialogo

----------------------------------------------------------------------- metodo de la interfaz ActionListener

Overridepublic void actionPerformed(ActionEvent e)

if(egetSource()==btnexaminar)

AbrirDialogo()if(egetSource()==btnagregar)

AlumnoDao alumnoDao=new AlumnoDao()asignarDatos()mensaje= alumnoDaograbarAlumno(alumnoVO)

if (mensaje==null)cudroMensaje(Datos de alumno registrado)

elsecudroMensaje(Error +mensaje)

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1012

983120983265983143983145983150983137 983089983088 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

if(egetSource()==btnbuscar)Buscaralumno rf=new Buscaralumno()

rfshow()

fin del metodo actionPerformed

---------------------------------------------------------------------- encapsular datos en el objeto alumnoVOpublic void asignarDatos()

alumnoVO=new AlumnoVO()alumnoVOsetNombres(txtnombresgetText())alumnoVOsetApellidos(txtapellidosgetText())alumnoVOsetFoto(txtfotogetText())

fin del metodo AsignarDatos

public void cudroMensaje(String mensaje)JOptionPaneshowMessageDialog(null mensaje)

fin de la clase Presentacion

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1112

983120983265983143983145983150983137 983089983089 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

(Se utilizoacute el asistente para crear este formulario)

private void txtcodigoKeyPressed(javaawteventKeyEvent evt) if(evtgetKeyCode()==evtVK_ENTER)

Image fotoAlumnoDao a=new AlumnoDao()

try AlumnoVO alumnoVO=agetDatosAlumno(IntegerparseInt(txtcodigogetText()))

setTitle(alumnoVOgetNombres()+ +alumnoVOgetApellidos())

foto=abuscarAlumno(IntegerparseInt(txtcodigogetText()))

foto=fotogetScaledInstance(300 300ImageSCALE_DEFAULT)

lblvistaFotosetIcon(new ImageIcon(foto))

thissetLocationRelativeTo(null)

catch (SQLException ex)

catch (IOException ex)

txtcodigo

lblvistaFoto

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1212

983120983265983143983145983150983137 983089983090 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

package pecomacademiapresentacion

import javaawtBorderLayoutimport javaxswingJFrame

public class Principal extends JFramepublic Principal()

getContentPane()add(new Registraralumno () BorderLayoutCENTER)meacutetodo principal

public static void main(String []args)Principal p=new Principal()psetTitle(Alumno)psetSize(700 400)psetLocationRelativeTo(null)psetVisible(true)

fin del meacutetodo principal

Page 10: Leng Prog II Grabar y Leer Imagnes

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1012

983120983265983143983145983150983137 983089983088 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

if(egetSource()==btnbuscar)Buscaralumno rf=new Buscaralumno()

rfshow()

fin del metodo actionPerformed

---------------------------------------------------------------------- encapsular datos en el objeto alumnoVOpublic void asignarDatos()

alumnoVO=new AlumnoVO()alumnoVOsetNombres(txtnombresgetText())alumnoVOsetApellidos(txtapellidosgetText())alumnoVOsetFoto(txtfotogetText())

fin del metodo AsignarDatos

public void cudroMensaje(String mensaje)JOptionPaneshowMessageDialog(null mensaje)

fin de la clase Presentacion

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1112

983120983265983143983145983150983137 983089983089 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

(Se utilizoacute el asistente para crear este formulario)

private void txtcodigoKeyPressed(javaawteventKeyEvent evt) if(evtgetKeyCode()==evtVK_ENTER)

Image fotoAlumnoDao a=new AlumnoDao()

try AlumnoVO alumnoVO=agetDatosAlumno(IntegerparseInt(txtcodigogetText()))

setTitle(alumnoVOgetNombres()+ +alumnoVOgetApellidos())

foto=abuscarAlumno(IntegerparseInt(txtcodigogetText()))

foto=fotogetScaledInstance(300 300ImageSCALE_DEFAULT)

lblvistaFotosetIcon(new ImageIcon(foto))

thissetLocationRelativeTo(null)

catch (SQLException ex)

catch (IOException ex)

txtcodigo

lblvistaFoto

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1212

983120983265983143983145983150983137 983089983090 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

package pecomacademiapresentacion

import javaawtBorderLayoutimport javaxswingJFrame

public class Principal extends JFramepublic Principal()

getContentPane()add(new Registraralumno () BorderLayoutCENTER)meacutetodo principal

public static void main(String []args)Principal p=new Principal()psetTitle(Alumno)psetSize(700 400)psetLocationRelativeTo(null)psetVisible(true)

fin del meacutetodo principal

Page 11: Leng Prog II Grabar y Leer Imagnes

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1112

983120983265983143983145983150983137 983089983089 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

(Se utilizoacute el asistente para crear este formulario)

private void txtcodigoKeyPressed(javaawteventKeyEvent evt) if(evtgetKeyCode()==evtVK_ENTER)

Image fotoAlumnoDao a=new AlumnoDao()

try AlumnoVO alumnoVO=agetDatosAlumno(IntegerparseInt(txtcodigogetText()))

setTitle(alumnoVOgetNombres()+ +alumnoVOgetApellidos())

foto=abuscarAlumno(IntegerparseInt(txtcodigogetText()))

foto=fotogetScaledInstance(300 300ImageSCALE_DEFAULT)

lblvistaFotosetIcon(new ImageIcon(foto))

thissetLocationRelativeTo(null)

catch (SQLException ex)

catch (IOException ex)

txtcodigo

lblvistaFoto

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1212

983120983265983143983145983150983137 983089983090 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

package pecomacademiapresentacion

import javaawtBorderLayoutimport javaxswingJFrame

public class Principal extends JFramepublic Principal()

getContentPane()add(new Registraralumno () BorderLayoutCENTER)meacutetodo principal

public static void main(String []args)Principal p=new Principal()psetTitle(Alumno)psetSize(700 400)psetLocationRelativeTo(null)psetVisible(true)

fin del meacutetodo principal

Page 12: Leng Prog II Grabar y Leer Imagnes

7182019 Leng Prog II Grabar y Leer Imagnes

httpslidepdfcomreaderfullleng-prog-ii-grabar-y-leer-imagnes 1212

983120983265983143983145983150983137 983089983090 983140983141 983089983090

UNIVERSIDAD NACIONAL TECNOLOacuteGICA DEL CONO SUR DE LIMA

ESCUELA PROFESIONAL DE INGENIERIA DE SISTEMAS

package pecomacademiapresentacion

import javaawtBorderLayoutimport javaxswingJFrame

public class Principal extends JFramepublic Principal()

getContentPane()add(new Registraralumno () BorderLayoutCENTER)meacutetodo principal

public static void main(String []args)Principal p=new Principal()psetTitle(Alumno)psetSize(700 400)psetLocationRelativeTo(null)psetVisible(true)

fin del meacutetodo principal