Você está na página 1de 34

Tutorial Crear Aplicacin JAVA

TUTORIAL CREAR APLICACIN JAVA

CARLOS ANDRES MARTINEZ CARO

SENA ADSI 2015

1
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

TUTORIAL CREAR APLICACIN JAVA

INTRODUCCIN 02
Sesin 1: Construyendo la base de datos 03
Sesin 2: Desarrollando la Interfaz Grfica de Usuario (GUI) 25
Sesin 3: Creando el Modelo de la Aplicacin 46
Sesin 4: Enlazando con el Controlador 56
Sesin 5: Probando el Modelo Vista Controlador MVC 70
Sesin 6: Accediendo a la Base de Datos con JDBC 78
Sesin 7: Accediendo a la Base de Datos con JPA 89
Sesin 8: Generando reportes impresos 108

2
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

TUTORIAL PARA CREAR APLICACIONES CON JAVA

Sesin 1: Construyendo la base de datos

TABLAS

1.1. CITAS

3
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

1.2. CONSULTORIOS

1.3. MEDICOS

4
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

1.4. PACIENTES

1.5. TRATAMIENTO

5
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

Sesin 2: Desarrollando la Interfaz Grfica del Usuario (GUI)

6
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

7
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

Sesin 3: CREANDO EL MODELO DE APLICACIN

Clase paciente
/*
ADSI SENA
CARLOS ANDRES MARTINEZ CARO
*/
package modelo;

public class Paciente {


private String identificacion;
private String nombres;
private String apellidos;
private String fechaNacimiento;
private String sexo;

public Paciente (String id, String nom, String ape, String fechaNac, String sex)
{
identificacion=id;
nombres=nom;
apellidos=ape;
fechaNacimiento=fechaNac;
sexo=sex;
}
/**
* @return the identificacion
*/
public String getIdentificacion() {
return identificacion;
}

/**
* @param identificacion the identificacion to set
*/
public void setIdentificacion(String identificacion) {
this.identificacion = identificacion;
}

/**
* @return the nombres
*/
public String getNombres() {
return nombres;
}

/**
* @param nombres the nombres to set
*/
public void setNombres(String nombres) {
this.nombres = nombres;

8
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

/**
* @return the apellidos
*/
public String getApellidos() {
return apellidos;
}

/**
* @param apellidos the apellidos to set
*/
public void setApellidos(String apellidos) {
this.apellidos = apellidos;
}

/**
* @return the fechaNacimiento
*/
public String getFechaNacimiento() {
return fechaNacimiento;
}

/**
* @param fechaNacimiento the fechaNacimiento to set
*/
public void setFechaNacimiento(String fechaNacimiento) {
this.fechaNacimiento = fechaNacimiento;
}

/**
* @return the sexo
*/
public String getSexo() {
return sexo;
}

/**
* @param sexo the sexo to set
*/
public void setSexo(String sexo) {
this.sexo = sexo;
}
}

Clase gestor paciente


/*
ADSI SENA 2015
CARLOS ANDRES MARTINEZ CARO
*/
package modelo;

9
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

import java.util.LinkedList;
import java.sql.*;
import javax.swing.JOptionPane;

public class GestorPaciente


{

private static Connection conn;

public GestorPaciente()
{
recurso.Conexion conexion= new recurso.Conexion ("localhost","XE", "citas", "citas");
conn = conexion.getConexion();
}
public void registrarPaciente (Paciente paciente)
{
try
{
PreparedStatement pst = conn.prepareStatement("insert into PACIENTES values (?,?,?,?,?)");
pst.setString(1, paciente.getIdentificacion());
pst.setString(2, paciente.getNombres());
pst.setString(3,paciente.getApellidos());
pst.setString(4,paciente.getFechaNacimiento());
pst.setString(5,paciente.getSexo());
pst.executeUpdate();
JOptionPane.showMessageDialog(null,"paciente Registrado");
}
catch(SQLException exc)
{
JOptionPane.showMessageDialog(null, exc.getMessage());
}
}
public LinkedList<Paciente> getPacientesBy (int parametro, String valor)
{
LinkedList<Paciente> resultado = new LinkedList<Paciente>();
String sql="";
switch (parametro)
{
case 1: sql = "select * from PACIENTES where pacIdentificacion ='"+valor+"`";
break;
case 2: sql ="select * from PACIENTES where pacNombres ='"+valor+"`";
break;
case 3: sql ="select * from PACIENTES where pacApellido ='"+valor+"`";
break;
case 4: sql ="select * from PACIENTES where pacSexo ='"+valor+"`";
break;
}
try
{
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql);
while(rs.next())

1
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

{
resultado.add(new Paciente (rs.getString("pacIdentificacion"),
rs.getString("pacNombres"),
rs.getString("pacApellidos"),
rs.getString("pacFechaNacimiento"),
rs.getString("pacSexo")));
}
st.close();
rs.close();
}
catch (SQLException exc)
{
JOptionPane.showMessageDialog(null, exc.getMessage());
}
finally
{
return resultado;
}
}
}

Sesin 4: ENLAZANDO CON EL CONTROLADOR


Clase Paciente Control
/*
SENA ADSI 2015
CARLOS ANDRES MARTINEZ CARO
*/
package controlador;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;

public class PacienteControl implements ActionListener


{
vista.RegPacienteInternalFrame pacienteVista;
modelo.Paciente pacienteModelo;
modelo.GestorPaciente gestorPacienteModelo;

public PacienteControl (vista.RegPacienteInternalFrame pacienteVista)


{
this.pacienteVista = pacienteVista;
gestorPacienteModelo= new modelo.GestorPaciente();

@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource().equals(pacienteVista.RegistrarBtn))

1
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

{
String identificacion=pacienteVista.IdentificacionTxt.getText();
String nombres=pacienteVista.NombresTxt.getText();
String apellidos=pacienteVista.ApellidosTxt.getText();
SimpleDateFormat formato = new SimpleDateFormat ("dd/MM/yyyy");
String fechaNacimiento=formato.format(pacienteVista.FechaNacimientoDtc.getDate());
String sexo=null;

if(pacienteVista.MasculinoOpt.isSelected())
sexo="m";
else
sexo="f";
pacienteModelo=new modelo.Paciente(identificacion,nombres, apellidos,fechaNacimiento, sexo);
gestorPacienteModelo.registrarPaciente (pacienteModelo);
}
if(e.getSource().equals(pacienteVista.NuevoBtn))
{
pacienteVista.IdentificacionTxt.setText(null);
pacienteVista.NombresTxt.setText(null);
pacienteVista.ApellidosTxt.setText(null);
pacienteVista.FechaNacimientoDtc.setDate(null);
pacienteVista.MasculinoOpt.setSelected(false);
pacienteVista.FemeninoOpt.setSelected(false);
pacienteVista.IdentificacionTxt.requestFocus();

}
}
}

Clase controlador gestor paciente control

/*
SENA ADSI 2015
CARLOS ANDRES MARTINEZ CARO
*/
package controlador;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;

public class GestorPacienteControl implements ActionListener


{
modelo.GestorPaciente pacientesModelo;
vista.ConsPacienteInternalFrame consultarPacienteVista;

public GestorPacienteControl (vista.ConsPacienteInternalFrame consultarPacienteVista)

1
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

{
this.consultarPacienteVista=consultarPacienteVista;
pacientesModelo=new modelo.GestorPaciente();

}
@Override
public void actionPerformed(ActionEvent e)
{
String valor=consultarPacienteVista.ValorTxt.getText();
int parametro=0;
consultarPacienteVista.getTableModel().setRowCount (0);
consultarPacienteVista.getTableModel().fireTableDataChanged();
if (consultarPacienteVista.IdentificacionOpt.isSelected())
parametro=1;
if (consultarPacienteVista.NombresOpt.isSelected())
parametro=2;
if (consultarPacienteVista.ApellidosOpt.isSelected())
parametro=3;
if (consultarPacienteVista.SexoOpt.isSelected())
parametro=4;
LinkedList<modelo.Paciente> pacientes = pacientesModelo.getPacientesBy (parametro, valor);
String registro[] = new String [5];
for(modelo.Paciente p:pacientes)
{
registro[0]=p.getIdentificacion();
registro[1]=p.getNombres();
registro[2]=p.getApellidos();
registro[3]=p.getFechaNacimiento();
registro[4]=p.getSexo();
consultarPacienteVista.getTableModel().addRow (registro);
consultarPacienteVista.getTableModel().fireTableDataChanged();
}
}
}

Sesin 5: Probando el Modelo Vista Controlador

Formulario principal

/*
SENA ADSI 2015
CARLOS ANDRES MARTINEZ CARO
*/
package vista;

public class PrincipalJFrame extends javax.swing.JFrame {

1
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

RegPacienteInternalFrame regPacienteInternalFrame;
ConsPacienteInternalFrame consPacienteInternalFrame;
public PrincipalJFrame()
{
regPacienteInternalFrame = new RegPacienteInternalFrame();
consPacienteInternalFrame = new ConsPacienteInternalFrame();
add (regPacienteInternalFrame);
add (consPacienteInternalFrame);
initComponents();
setExtendedState (MAXIMIZED_BOTH);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jMenuBar1 = new javax.swing.JMenuBar();


jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
jMenuItem2 = new javax.swing.JMenuItem();
jMenuItem3 = new javax.swing.JMenuItem();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("GESTIN DE CITAS");
setName("PrincipalJFrame"); // NOI18N

jMenu1.setText("Archivo");
jMenu1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenu1ActionPerformed(evt);
}
});

jMenuItem1.setText("Salir");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem1);

jMenuBar1.add(jMenu1);

jMenu2.setText("Pacientes");
jMenu2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenu2ActionPerformed(evt);
}
});

jMenuItem2.setText("Registrar");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {

1
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

public void actionPerformed(java.awt.event.ActionEvent evt) {


jMenuItem2ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem2);

jMenuItem3.setText("Consultar");
jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem3ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem3);

jMenuBar1.add(jMenu2);

setJMenuBar(jMenuBar1);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());


getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 279, Short.MAX_VALUE)
);

pack();
}// </editor-fold>

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {


System.exit(0);
}

private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
}

private void jMenu2ActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
}

private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {


regPacienteInternalFrame.setVisible(true);//
}

private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {


consPacienteInternalFrame.setVisible(true);//
}

1
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {

java.util.logging.Logger.getLogger(PrincipalJFrame.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(PrincipalJFrame.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(PrincipalJFrame.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(PrincipalJFrame.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
}
//</editor-fold>

/* Create and display the form */


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new PrincipalJFrame().setVisible(true);
}
});
}

// Variables declaration - do not modify


private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
// End of variables declaration

1
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

ConsPacienteInternalFrame
/*
SENA ADSI 2015
CARLOS ANDRES MARTINEZ CARO
*/
package vista;

import javax.swing.table.DefaultTableModel;

public class ConsPacienteInternalFrame extends javax.swing.JInternalFrame


{
private controlador.GestorPacienteControl gestorpacientesControl;
private DefaultTableModel tabla;

public ConsPacienteInternalFrame()
{
initComponents();
gestorpacientesControl=new controlador.GestorPacienteControl (this);
String titulosTabla[]={"Identificacion","Nombres","Apellidos","Fecha Nac","sexo"};
tabla = new DefaultTableModel(null, titulosTabla);
ResultadosTbl.setModel(tabla);
AceptarBtn.addActionListener(gestorpacientesControl);//
}
public DefaultTableModel getTableModel()
{
return tabla;
}

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

IdentificacionOpt = new javax.swing.JRadioButton();


NombresOpt = new javax.swing.JRadioButton();
ApellidosOpt = new javax.swing.JRadioButton();
SexoOpt = new javax.swing.JRadioButton();
jLabel1 = new javax.swing.JLabel();
ValorTxt = new javax.swing.JTextField();
AceptarBtn = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
ResultadosTbl = new javax.swing.JTable();

IdentificacionOpt.setText("Identificacin");
IdentificacionOpt.setName("IdentificacionOpt"); // NOI18N
IdentificacionOpt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
IdentificacionOptActionPerformed(evt);
}

1
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

});

NombresOpt.setText("Nombres");
NombresOpt.setName("NombresOpt"); // NOI18N

ApellidosOpt.setText("Apellidos");
ApellidosOpt.setName("ApellidosOpt"); // NOI18N

SexoOpt.setText("Sexo");
SexoOpt.setName("SexoOpt"); // NOI18N

jLabel1.setText("Valor a Buscar");

ValorTxt.setName("ValorTxt"); // NOI18N

AceptarBtn.setText("Aceptar");
AceptarBtn.setName("AceptarBtn"); // NOI18N

ResultadosTbl.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
ResultadosTbl.setName("ResultadosTbl"); // NOI18N
jScrollPane1.setViewportView(ResultadosTbl);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());


getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 452,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(IdentificacionOpt)
.addGroup(layout.createSequentialGroup()
.addGap(11, 11, 11)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 68,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()

1
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

.addComponent(ValorTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 284,


javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(AceptarBtn))
.addGroup(layout.createSequentialGroup()
.addComponent(NombresOpt)
.addGap(18, 18, 18)
.addComponent(ApellidosOpt)
.addGap(18, 18, 18)
.addComponent(SexoOpt)))))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(IdentificacionOpt)
.addComponent(NombresOpt)
.addComponent(ApellidosOpt)
.addComponent(SexoOpt))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(ValorTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(AceptarBtn))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 283,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

pack();
}// </editor-fold>

private void IdentificacionOptActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
}

// Variables declaration - do not modify


private javax.swing.JButton AceptarBtn;
public javax.swing.JRadioButton ApellidosOpt;
public javax.swing.JRadioButton IdentificacionOpt;
public javax.swing.JRadioButton NombresOpt;
public javax.swing.JTable ResultadosTbl;
public javax.swing.JRadioButton SexoOpt;
public javax.swing.JTextField ValorTxt;
private javax.swing.JLabel jLabel1;
private javax.swing.JScrollPane jScrollPane1;
// End of variables declaration

1
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

RegPacienteInternalFrame
/*
SENA ADSI 2015
CARLOS ANDRES MARTINEZ CARO
*/
package vista;

public class RegPacienteInternalFrame extends javax.swing.JInternalFrame {


private controlador.PacienteControl pacienteControlador;
public RegPacienteInternalFrame() {
initComponents();
pacienteControlador = new controlador.PacienteControl(this);
RegistrarBtn.addActionListener(pacienteControlador);
NuevoBtn.addActionListener(pacienteControlador);
}

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jCheckBoxMenuItem1 = new javax.swing.JCheckBoxMenuItem();


jDateChooser1 = new com.toedter.calendar.JDateChooser();
IdentificacionTxt = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
NombresTxt = new javax.swing.JTextField();
ApellidosTxt = new javax.swing.JTextField();
MasculinoOpt = new javax.swing.JRadioButton();
FemeninoOpt = new javax.swing.JRadioButton();
RegistrarBtn = new javax.swing.JButton();
NuevoBtn = new javax.swing.JButton();
FechaNacimientoDtc = new com.toedter.calendar.JDateChooser();

jCheckBoxMenuItem1.setSelected(true);
jCheckBoxMenuItem1.setText("jCheckBoxMenuItem1");

setTitle("Registro de Pacientes");

IdentificacionTxt.setName("IdentificacionTxt"); // NOI18N
IdentificacionTxt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
IdentificacionTxtActionPerformed(evt);
}
});

2
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

jLabel1.setText("Identificacin:");

jLabel2.setText("Nombre: ");

jLabel3.setText("Apellidos");

jLabel4.setText("Fecha de Nacimiento");

jLabel5.setText("Sexo");

NombresTxt.setName("NombresTxt"); // NOI18N

ApellidosTxt.setName("ApellidosTxt"); // NOI18N
ApellidosTxt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ApellidosTxtActionPerformed(evt);
}
});

MasculinoOpt.setText("M");
MasculinoOpt.setName("MasculinoOpt"); // NOI18N
MasculinoOpt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
MasculinoOptActionPerformed(evt);
}
});

FemeninoOpt.setText("F");
FemeninoOpt.setName("FemeninoOpt"); // NOI18N

RegistrarBtn.setText("Registrar");
RegistrarBtn.setName("RegistrarBtn"); // NOI18N
RegistrarBtn.setOpaque(false);
RegistrarBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
RegistrarBtnActionPerformed(evt);
}
});

NuevoBtn.setText("Nuevo");
NuevoBtn.setName("NuevoBtn"); // NOI18N
NuevoBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
NuevoBtnActionPerformed(evt);
}
});

FechaNacimientoDtc.setName("FechaNacimientoDtc"); // NOI18N
FechaNacimientoDtc.setOpaque(false);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

2
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(43, 43, 43)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 85,
Short.MAX_VALUE)
.addComponent(IdentificacionTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 159,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(58, 58, 58))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel4)
.addComponent(jLabel3))
.addGap(54, 54, 54)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(ApellidosTxt)
.addComponent(NombresTxt)
.addComponent(FechaNacimientoDtc, javax.swing.GroupLayout.DEFAULT_SIZE, 159,
Short.MAX_VALUE))
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel5)
.addGap(80, 80, 80)
.addComponent(MasculinoOpt)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(FemeninoOpt)
.addGroup(layout.createSequentialGroup()
.addComponent(RegistrarBtn)
.addGap(18, 18, 18)
.addComponent(NuevoBtn)))
.addGap(47, 47, 47))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(24, 24, 24)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(IdentificacionTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(NombresTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)

2
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(ApellidosTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addComponent(FechaNacimientoDtc, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(MasculinoOpt)
.addComponent(FemeninoOpt))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34,
Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(RegistrarBtn)
.addComponent(NuevoBtn))
.addGap(22, 22, 22))
);

pack();
}// </editor-fold>

private void IdentificacionTxtActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
}

private void MasculinoOptActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
}

private void RegistrarBtnActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
}

private void NuevoBtnActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
}

private void ApellidosTxtActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
}

// Variables declaration - do not modify


public javax.swing.JTextField ApellidosTxt;
public com.toedter.calendar.JDateChooser FechaNacimientoDtc;
public javax.swing.JRadioButton FemeninoOpt;
public javax.swing.JTextField IdentificacionTxt;
public javax.swing.JRadioButton MasculinoOpt;

2
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

public javax.swing.JTextField NombresTxt;


public javax.swing.JButton NuevoBtn;
public javax.swing.JButton RegistrarBtn;
private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem1;
private com.toedter.calendar.JDateChooser jDateChooser1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
// End of variables declaration
}

SESIN 6: ACCEDIENDO A LA BASE DE DATOS CON JDBC

CONEXION
/*
SENA ADSI 2015
CARLOS ANDRES MARTINEZ CARO
*/
package recurso;

import java.sql.*;
import javax.swing.JOptionPane;

public class Conexion {


private String driver, url, ip, bd, usr, pass;
private Connection conexion;

public Conexion(String ip, String bd, String usr, String pass)


{
driver = "oracle.jdbc.driver.OracleDriver";
this.bd = bd;
this.usr = usr;
this.pass = pass;
url = "jdbc:oracle:thin:@" + ip + ":1521:" + bd;
try
{
Class.forName(driver).newInstance();
conexion = DriverManager.getConnection(url, usr, pass);
}
catch (Exception exc)
{
JOptionPane.showMessageDialog(null, "Error de conexion con la base de datos");
}

}
public Connection getConexion()
{
return conexion;

2
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

}
public Connection CerrarConexion() throws SQLException
{
conexion.close();
conexion = null;
return conexion;
}
}

SESIN 7: ACCEDIENDO A LA BASE DE DATOS CON JPA

PACIENTES
/*
SENA ADSI
CARLOS ANDRES MARTINEZ CARO
*/
package modelo;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
*
* @author bibli
*/
@Entity
@Table(name = "PACIENTES")
@NamedQueries({
@NamedQuery(name = "Pacientes.findAll", query = "SELECT p FROM Pacientes p")})
public class Pacientes implements Serializable {

private static final long serialVersionUID = 1L;


@Id
@Basic(optional = false)
@Column(name = "PACIDENTIFICACION")
private String pacidentificacion;
@Basic(optional = false)
@Column(name = "PACNOMBRES")
private String pacnombres;
@Basic(optional = false)
@Column(name = "PACAPELLIDOS")
private String pacapellidos;

2
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

@Column(name = "PACFECHANACIMIENTO")
@Temporal(TemporalType.TIMESTAMP)
private Date pacfechanacimiento;
@Column(name = "PACSEXO")
private Character pacsexo;

public Pacientes() {
}

public Pacientes(String pacidentificacion) {


this.pacidentificacion = pacidentificacion;
}

public Pacientes(String pacidentificacion, String pacnombres, String pacapellidos) {


this.pacidentificacion = pacidentificacion;
this.pacnombres = pacnombres;
this.pacapellidos = pacapellidos;
}

public String getPacidentificacion() {


return pacidentificacion;
}

public void setPacidentificacion(String pacidentificacion) {


this.pacidentificacion = pacidentificacion;
}

public String getPacnombres() {


return pacnombres;
}

public void setPacnombres(String pacnombres) {


this.pacnombres = pacnombres;
}

public String getPacapellidos() {


return pacapellidos;
}

public void setPacapellidos(String pacapellidos) {


this.pacapellidos = pacapellidos;
}

public Date getPacfechanacimiento() {


return pacfechanacimiento;
}

public void setPacfechanacimiento(Date pacfechanacimiento) {


this.pacfechanacimiento = pacfechanacimiento;
}

public Character getPacsexo() {

2
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

return pacsexo;
}

public void setPacsexo(Character pacsexo) {


this.pacsexo = pacsexo;
}

@Override
public int hashCode() {
int hash = 0;
hash += (pacidentificacion != null ? pacidentificacion.hashCode() : 0);
return hash;
}

@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Pacientes)) {
return false;
}
Pacientes other = (Pacientes) object;
if ((this.pacidentificacion == null && other.pacidentificacion != null) || (this.pacidentificacion != null &&
!this.pacidentificacion.equals(other.pacidentificacion))) {
return false;
}
return true;
}

@Override
public String toString() {
return "modelo.Pacientes[ pacidentificacion=" + pacidentificacion + " ]";
}

PACIENTESJPACONTROLER

/*
SENA ADSI
CARLOS ANDRES MARTINEZ CARO
*/
package modelo;

import java.io.Serializable;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Query;
import javax.persistence.EntityNotFoundException;
import javax.persistence.criteria.CriteriaQuery;

2
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

import javax.persistence.criteria.Root;
import modelo.exceptions.NonexistentEntityException;
import modelo.exceptions.PreexistingEntityException;

/**
*
* @author bibli
*/
public class PacientesJpaController implements Serializable {

public PacientesJpaController(EntityManagerFactory emf) {


this.emf = emf;
}
private EntityManagerFactory emf = null;

public EntityManager getEntityManager() {


return emf.createEntityManager();
}

public void create(Pacientes pacientes) throws PreexistingEntityException, Exception {


EntityManager em = null;
try {
em = getEntityManager();
em.getTransaction().begin();
em.persist(pacientes);
em.getTransaction().commit();
} catch (Exception ex) {
if (findPacientes(pacientes.getPacidentificacion()) != null) {
throw new PreexistingEntityException("Pacientes " + pacientes + " already exists.", ex);
}
throw ex;
} finally {
if (em != null) {
em.close();
}
}
}

public void edit(Pacientes pacientes) throws NonexistentEntityException, Exception {


EntityManager em = null;
try {
em = getEntityManager();
em.getTransaction().begin();
pacientes = em.merge(pacientes);
em.getTransaction().commit();
} catch (Exception ex) {
String msg = ex.getLocalizedMessage();
if (msg == null || msg.length() == 0) {
String id = pacientes.getPacidentificacion();
if (findPacientes(id) == null) {
throw new NonexistentEntityException("The pacientes with id " + id + " no longer exists.");
}

2
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

}
throw ex;
} finally {
if (em != null) {
em.close();
}
}
}

public void destroy(String id) throws NonexistentEntityException {


EntityManager em = null;
try {
em = getEntityManager();
em.getTransaction().begin();
Pacientes pacientes;
try {
pacientes = em.getReference(Pacientes.class, id);
pacientes.getPacidentificacion();
} catch (EntityNotFoundException enfe) {
throw new NonexistentEntityException("The pacientes with id " + id + " no longer exists.", enfe);
}
em.remove(pacientes);
em.getTransaction().commit();
} finally {
if (em != null) {
em.close();
}
}
}

public List<Pacientes> findPacientesEntities() {


return findPacientesEntities(true, -1, -1);
}

public List<Pacientes> findPacientesEntities(int maxResults, int firstResult) {


return findPacientesEntities(false, maxResults, firstResult);
}

private List<Pacientes> findPacientesEntities(boolean all, int maxResults, int firstResult) {


EntityManager em = getEntityManager();
try {
CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
cq.select(cq.from(Pacientes.class));
Query q = em.createQuery(cq);
if (!all) {
q.setMaxResults(maxResults);
q.setFirstResult(firstResult);
}
return q.getResultList();
} finally {
em.close();
}

2
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

public Pacientes findPacientes(String id) {


EntityManager em = getEntityManager();
try {
return em.find(Pacientes.class, id);
} finally {
em.close();
}
}

public int getPacientesCount() {


EntityManager em = getEntityManager();
try {
CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
Root<Pacientes> rt = cq.from(Pacientes.class);
cq.select(em.getCriteriaBuilder().count(rt));
Query q = em.createQuery(cq);
return ((Long) q.getSingleResult()).intValue();
} finally {
em.close();
}
}

PACIENTECONTROL
/*
SENA ADSI 2015
CARLOS ANDRES MARTINEZ CARO
*/
package controlador;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.swing.JOptionPane;
import modelo.exceptions.PreexistingEntityException;

public class PacienteControl implements ActionListener


{
vista.RegPacienteInternalFrame pacienteVista;
modelo.Pacientes pacienteModelo;
modelo.PacientesJpaController gestorPacienteModelo;

public PacienteControl (vista.RegPacienteInternalFrame pacienteVista)


{
this.pacienteVista = pacienteVista;

3
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

EntityManagerFactory emf= Persistence.createEntityManagerFactory("proyectoCitasPU");


gestorPacienteModelo = new modelo.PacientesJpaController(emf);
}

@Override
public void actionPerformed(ActionEvent e)
{
if(e.getSource().equals(pacienteVista.RegistrarBtn))
{
String identificacion=pacienteVista.IdentificacionTxt.getText();
String nombres=pacienteVista.NombresTxt.getText();
String apellidos=pacienteVista.ApellidosTxt.getText();
SimpleDateFormat formato = new SimpleDateFormat ("dd/MM/yyyy");
String fechaNacimiento=formato.format(pacienteVista.FechaNacimientoDtc.getDate());
char sexo='\0';
if(pacienteVista.MasculinoOpt.isSelected())
sexo='m';
else
sexo='f';

pacienteModelo=new modelo.Pacientes();
pacienteModelo.setPacidentificacion(identificacion);
pacienteModelo.setPacapellidos(apellidos);
pacienteModelo.setPacnombres(nombres);
pacienteModelo.setPacfechanacimiento(new Date (fechaNacimiento));
pacienteModelo.setPacsexo(sexo);

try
{
gestorPacienteModelo.create(pacienteModelo);
JOptionPane.showMessageDialog(pacienteVista, "Paciente registrado correctamente");
}
catch (PreexistingEntityException ex)
{
JOptionPane.showMessageDialog(pacienteVista,"El paciente ya existe");
}
catch (Exception ex)
{
JOptionPane.showMessageDialog(pacienteVista, ex.getMessage());
}
}
if(e.getSource().equals(pacienteVista.NuevoBtn))
{
pacienteVista.IdentificacionTxt.setText(null);
pacienteVista.NombresTxt.setText(null);
pacienteVista.ApellidosTxt.setText(null);
pacienteVista.FechaNacimientoDtc.setDate(null);
pacienteVista.MasculinoOpt.setSelected(false);
pacienteVista.FemeninoOpt.setSelected(false);
pacienteVista.IdentificacionTxt.requestFocus();

3
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

}
}

GestorPacienteControl

/*
SENA ADSI 2015
CARLOS ANDRES MARTINEZ CARO
*/
package controlador;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class GestorPacienteControl implements ActionListener


{
modelo.PacientesJpaController pacientesModelo;
vista.ConsPacienteInternalFrame consultarPacienteVista;

public GestorPacienteControl (vista.ConsPacienteInternalFrame consultarPacienteVista)


{
this.consultarPacienteVista=consultarPacienteVista;
EntityManagerFactory emf= Persistence.createEntityManagerFactory("ProyectoCitasPU");
pacientesModelo=new modelo.PacientesJpaController(emf);

}
@Override
public void actionPerformed(ActionEvent e)
{
String valor=consultarPacienteVista.ValorTxt.getText();
int parametro=0;
consultarPacienteVista.getTableModel().setRowCount (0);
consultarPacienteVista.getTableModel().fireTableDataChanged();
if (consultarPacienteVista.IdentificacionOpt.isSelected())
parametro=1;
if (consultarPacienteVista.NombresOpt.isSelected())
parametro=2;
if (consultarPacienteVista.ApellidosOpt.isSelected())
parametro=3;
if (consultarPacienteVista.SexoOpt.isSelected())
parametro=4;
List<modelo.Pacientes> pacientes = pacientesModelo.findPacientesEntities();
for(modelo.Pacientes p:pacientes)
{
switch(parametro)
{
case 1: if (p.getPacidentificacion().equals(valor))
mostrarEnTabla(p);
break;

3
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

case 2: if (p.getPacnombres().equals(valor))
mostrarEnTabla(p);
break;
case 3: if (p.getPacapellidos().equals(valor))
mostrarEnTabla(p);
break;
case 4: if (p.getPacsexo().toString().equals(valor))
mostrarEnTabla(p);
break;
}
}
}
private void mostrarEnTabla(modelo.Pacientes p)
{
String registro[] = new String [5];
registro[0]=p.getPacidentificacion();
registro[1]=p.getPacnombres();
registro[2]=p.getPacapellidos();
registro[3]=p.getPacfechanacimiento().toString();
registro[4]=p.getPacsexo().toString();
consultarPacienteVista.getTableModel().addRow (registro);
consultarPacienteVista.getTableModel().fireTableDataChanged();
}
}

INFORME
/*
SENA ADSI
CARLOS ANDRES MARTINEZ CARO
*/
package reportes;

import java.sql.Connection;
import java.sql.DriverManager;
import javax.swing.JOptionPane;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.view.JasperViewer;

public class GestorReportes


{
private static Connection conexion;

public GestorReportes()
{
String driver= "oracle.jdbc.driver.OracleDriver";
String url= "jdbc:oracle:thin:@localhost:1521:XE";
try

3
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje
Tutorial Crear Aplicacin JAVA

{
Class.forName(driver).newInstance();
conexion=DriverManager.getConnection(url,"citas","citas");
}
catch (Exception ex)
{
JOptionPane.showMessageDialog(null,"Error dseconexion database");
}
}
public void ejecutarReporte (String archivo)
{
try
{
String Reporte = System.getProperty("user.dir") + "/src/reportes/"+archivo;
JasperReport masterReport = (JasperReport)JRLoader.loadObject(Reporte);
JasperPrint jasperPrint = JasperFillManager.fillReport(masterReport, null, conexion);
JasperViewer jviewer= new JasperViewer(jasperPrint,false);
jviewer.setVisible(true);
}
catch (Exception ex)
{
JOptionPane.showMessageDialog(null, "Error" +ex.getMessage());
}
}
}

3
FAVA- Formacin en Ambientes Virtuales de Aprendizaje SENA - Servicio Nacional de Aprendizaje

Você também pode gostar