Sei sulla pagina 1di 26

UNIVERSIDAD POLITCNICA DEL VALLE DE TOLUCA

NOMBRE DEL PROGRAMA EDUCATIVO:


INGENIERA EN INFORMTICA

NOMBRE DEL ASIGNATURA:


PROGRAMACIN ORIENTADA A OBJETOS

NOMBRE DE LA PRCTICA:

Interfaces graficas
NOMBRE DE LA UNIDAD DE APRENDIZAJE:

UNIDAD 4: INTERFACES GRAFICAS

FACILITADOR:
ING. LETICIA JAEL ROJAS ORTIZ
INTEGRANTES:

No
1

Matrcula
1417INI1
10

Nombre
DORIS SNCHEZ TORRES

MARZO, 2016

Nmero
de
Prctica:
Laboratori
o de:
Resultado
de
Aprendiza
je:
Justificaci
n:

Duracin (horas)

Marco
Terico:

Programacin Orientada a Objetos

COMPUTACION
Al concluir la unidad de aprendizaje el alumno ser capaz de
conocer las principales caractersticas de Java y las diferentes
interfaces que pueden ser utilizadas en dicho lenguaje, as mismo
emplearlas para desarrollar aplicaciones.
Conocer las principales caractersticas de Java
Conocer las principales caractersticas de interfaces de
Java
Utilizar y aplicar las distintas interfaces dentro del
desarrollo de aplicaciones Java
Emplear Interfaces grficas.

La programacin orientada a objetos (POO, u OOP segn sus


siglas en ingls) es un paradigma de programacin que usa
objetos en sus interacciones, para disear aplicaciones y
programas informticos.
Est basada en varias tcnicas, incluyendo herencia, cohesin,
abstraccin, polimorfismo, acoplamiento y encapsulamiento.
Java
Java es un lenguaje de programacin y una plataforma
informtica comercializada por primera vez en 1995 por Sun
Microsystems. Hay muchas aplicaciones y sitios web que no
funcionarn a menos que tenga Java instalado y cada da se
crean ms. Java es rpido, seguro y fiable. Desde porttiles hasta
centros de datos, desde consolas para juegos hasta sper
computadoras, desde telfonos mviles hasta Internet, Java est
en todas partes.
Interface
a) Interface: parte visible y pblica de una clase que describe
qu hace y cmo usarla. La documentacin de una clase en el API

de Java vendra siendo su interface.


b) Interface: parte visible y pblica de un mtodo que describe
qu hace y cmo usarlo (signatura del mtodo + instrucciones de
uso). La documentacin de un mtodo en el API de Java vendra
siendo su interface.
c) Interfaz Grfica de Usuario, interfaz de usuario o GUI
(Graphical User Interface): es el entorno de objetos grficos
disponibles para un usuario en el marco de una aplicacin o
sistema operativo. El sistema operativo MS-Dos se basaba en
intrpretes de comando (escritura de instrucciones por consola)
pero Windows se basa en una interfaz grfica de usuario (su
entorno de escritorio), Linux en otra y Macintosh en otra.
d) Herramientas para crear Interfaces grficas de usuario
en Java: Hacemos referencia principalmente a los paquetes
(packages) del API de Java swing y awt (Abstract Windowing
Toolkit). Las clases de estos paquetes permiten crear interfaces
grficas de usuario basadas en ventanas estilo Windows para
nuestras aplicaciones.

Material,
equipo y/o
reactivos:

Desarrollo
de la
Prctica:

e) Interfaces de Java: son unas entidades abstractas


conceptualmente por encima de las clases cuyo concepto vamos
a introducir a continuacin.
computadora
NetBeans
Gestor de Bases de datos

-CREAR EL DISEO DEL FORMULARIO

-CREAR LA BASE DE DATOS

-ESTABLECER MTODS PARA OBTENER LA INFORMACIN Y


ALMACENARLA EN VARIABLES

-REALIZAR LA CONEXION CON LA BASE DE DATOS

-MOSTRAR DATOS

INGRESAR DATOS:

MODIFICAR:

ELIMINAR:

CODIGO:
package PuntodeVenta;
import
import
import
import
import

java.sql.Connection;
java.sql.SQLException;
java.sql.Statement;
java.text.SimpleDateFormat;
javax.swing.JOptionPane;

/**
*
* @author Doris
*/
public class Alta_usr extends javax.swing.JFrame {
String nombre="";
String apellpat="";
String apellmat="";
String sexo="";
String edo="";
String educacion="";
String fecha="";
Boolean compu=false;
Boolean art=false;
Boolean deporte=false;
Boolean mus=false;

private static ConexionDB conexion;


public Alta_usr() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
buttonGroup2 = new javax.swing.ButtonGroup();
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();

jLabel6 = new javax.swing.JLabel();


jLabel7 = new javax.swing.JLabel();
Consultar = new javax.swing.JButton();
Guardar = new javax.swing.JButton();
txt_nombre = new javax.swing.JTextField();
txt_apepat = new javax.swing.JTextField();
txt_apemat = new javax.swing.JTextField();
radio_m = new javax.swing.JRadioButton();
radio_f = new javax.swing.JRadioButton();
radio_sol = new javax.swing.JRadioButton();
radio_cas = new javax.swing.JRadioButton();
radio_div = new javax.swing.JRadioButton();
Musica = new javax.swing.JCheckBox();
Deportes = new javax.swing.JCheckBox();
computacion = new javax.swing.JCheckBox();
Artes = new javax.swing.JCheckBox();
Educacion = new javax.swing.JComboBox();
DateChooser = new com.toedter.calendar.JDateChooser();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jPanel1 = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(new
org.netbeans.lib.awtextra.AbsoluteLayout());
jLabel1.setFont(new java.awt.Font("Tempus Sans ITC", 1, 18)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setText("Nombre:");
getContentPane().add(jLabel1, new
org.netbeans.lib.awtextra.AbsoluteConstraints(250, 40, -1, -1));
jLabel2.setFont(new java.awt.Font("Tempus Sans ITC", 1, 18)); // NOI18N
jLabel2.setForeground(new java.awt.Color(255, 255, 255));
jLabel2.setText("Apellido Paterno");
getContentPane().add(jLabel2, new
org.netbeans.lib.awtextra.AbsoluteConstraints(180, 80, -1, -1));
jLabel3.setFont(new java.awt.Font("Tempus Sans ITC", 1, 18)); // NOI18N
jLabel3.setForeground(new java.awt.Color(255, 255, 255));
jLabel3.setText("Apellido Marterno:");
getContentPane().add(jLabel3, new
org.netbeans.lib.awtextra.AbsoluteConstraints(160, 120, -1, -1));
jLabel4.setFont(new java.awt.Font("Tempus Sans ITC", 1, 18)); // NOI18N
jLabel4.setForeground(new java.awt.Color(255, 255, 255));
jLabel4.setText("Preferencias");
getContentPane().add(jLabel4, new
org.netbeans.lib.awtextra.AbsoluteConstraints(20, 400, 110, 30));
jLabel5.setFont(new java.awt.Font("Tempus Sans ITC", 1, 18)); // NOI18N

jLabel5.setForeground(new java.awt.Color(255, 255, 255));


jLabel5.setText("Sexo");
getContentPane().add(jLabel5, new
org.netbeans.lib.awtextra.AbsoluteConstraints(30, 190, -1, -1));
jLabel6.setFont(new java.awt.Font("Tempus Sans ITC", 1, 18)); // NOI18N
jLabel6.setForeground(new java.awt.Color(255, 255, 255));
jLabel6.setText("Estado Civil");
getContentPane().add(jLabel6, new
org.netbeans.lib.awtextra.AbsoluteConstraints(20, 260, -1, -1));
jLabel7.setFont(new java.awt.Font("Tempus Sans ITC", 1, 18)); // NOI18N
jLabel7.setForeground(new java.awt.Color(255, 255, 255));
jLabel7.setText("Educacion");
getContentPane().add(jLabel7, new
org.netbeans.lib.awtextra.AbsoluteConstraints(30, 320, -1, -1));
Consultar.setText("Consultar");
Consultar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ConsultarActionPerformed(evt);
} });
getContentPane().add(Consultar, new
org.netbeans.lib.awtextra.AbsoluteConstraints(660, 100, 90, 30));
Guardar.setText("Guardar");
Guardar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
GuardarActionPerformed(evt);
} });
getContentPane().add(Guardar, new
org.netbeans.lib.awtextra.AbsoluteConstraints(660, 50, 90, 30));
txt_nombre.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_nombreActionPerformed(evt);
}
});
getContentPane().add(txt_nombre, new
org.netbeans.lib.awtextra.AbsoluteConstraints(340, 40, 220, 30));
txt_apepat.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_apepatActionPerformed(evt);
}
});
getContentPane().add(txt_apepat, new
org.netbeans.lib.awtextra.AbsoluteConstraints(340, 80, 220, 30));
txt_apemat.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_apematActionPerformed(evt);
}
});

getContentPane().add(txt_apemat, new
org.netbeans.lib.awtextra.AbsoluteConstraints(340, 120, 220, 30));
radio_m.setBackground(new java.awt.Color(204, 204, 204));
buttonGroup1.add(radio_m);
radio_m.setFont(new java.awt.Font("Tempus Sans ITC", 1, 14)); // NOI18N
radio_m.setForeground(new java.awt.Color(255, 255, 255));
radio_m.setText("M");
radio_m.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
radio_mActionPerformed(evt);
}
});
getContentPane().add(radio_m, new
org.netbeans.lib.awtextra.AbsoluteConstraints(100, 190, -1, -1));
buttonGroup1.add(radio_f);
radio_f.setFont(new java.awt.Font("Tempus Sans ITC", 1, 14)); // NOI18N
radio_f.setForeground(new java.awt.Color(255, 255, 255));
radio_f.setText("F");
radio_f.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
radio_fActionPerformed(evt);
}
});
getContentPane().add(radio_f, new
org.netbeans.lib.awtextra.AbsoluteConstraints(170, 190, -1, -1));
buttonGroup2.add(radio_sol);
radio_sol.setFont(new java.awt.Font("Tempus Sans ITC", 1, 14)); // NOI18N
radio_sol.setForeground(new java.awt.Color(255, 255, 255));
radio_sol.setText("Soltero");
radio_sol.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
radio_solActionPerformed(evt);
}
});
getContentPane().add(radio_sol, new
org.netbeans.lib.awtextra.AbsoluteConstraints(140, 260, -1, -1));
buttonGroup2.add(radio_cas);
radio_cas.setFont(new java.awt.Font("Tempus Sans ITC", 1, 14)); // NOI18N
radio_cas.setForeground(new java.awt.Color(255, 255, 255));
radio_cas.setText("Cassdo");
getContentPane().add(radio_cas, new
org.netbeans.lib.awtextra.AbsoluteConstraints(240, 260, -1, -1));
buttonGroup2.add(radio_div);
radio_div.setFont(new java.awt.Font("Tempus Sans ITC", 1, 14)); // NOI18N
radio_div.setForeground(new java.awt.Color(255, 255, 255));
radio_div.setText("Divorciado");

radio_div.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
radio_divActionPerformed(evt);
}
});
getContentPane().add(radio_div, new
org.netbeans.lib.awtextra.AbsoluteConstraints(330, 260, -1, -1));
Musica.setFont(new java.awt.Font("Tempus Sans ITC", 1, 14)); // NOI18N
Musica.setForeground(new java.awt.Color(255, 255, 255));
Musica.setText("Musica");
Musica.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
MusicaActionPerformed(evt);
}
});
getContentPane().add(Musica, new
org.netbeans.lib.awtextra.AbsoluteConstraints(300, 450, -1, -1));
Deportes.setFont(new java.awt.Font("Tempus Sans ITC", 1, 14)); // NOI18N
Deportes.setForeground(new java.awt.Color(255, 255, 255));
Deportes.setText("Deportes");
Deportes.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
DeportesActionPerformed(evt);
}
});
getContentPane().add(Deportes, new
org.netbeans.lib.awtextra.AbsoluteConstraints(160, 440, -1, -1));
computacion.setBackground(new java.awt.Color(255, 255, 255));
computacion.setFont(new java.awt.Font("Tempus Sans ITC", 1, 14)); //
NOI18N
computacion.setForeground(new java.awt.Color(255, 255, 255));
computacion.setText("Computacion");
computacion.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
computacionActionPerformed(evt);
}
});
getContentPane().add(computacion, new
org.netbeans.lib.awtextra.AbsoluteConstraints(160, 400, -1, -1));
Artes.setFont(new java.awt.Font("Tempus Sans ITC", 1, 14)); // NOI18N
Artes.setForeground(new java.awt.Color(255, 255, 255));
Artes.setText("Arte");
Artes.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ArtesActionPerformed(evt);
}
});

getContentPane().add(Artes, new
org.netbeans.lib.awtextra.AbsoluteConstraints(300, 400, -1, -1));
Educacion.setModel(new javax.swing.DefaultComboBoxModel(new String[]
{ "primaria", "secundaria", "preperatoria", "universidaad" }));
getContentPane().add(Educacion, new
org.netbeans.lib.awtextra.AbsoluteConstraints(140, 320, 280, 30));
DateChooser.setDateFormatString("yyyy-MM-dd");
getContentPane().add(DateChooser, new
org.netbeans.lib.awtextra.AbsoluteConstraints(570, 270, 140, 20));
jButton1.setText("Eliminar");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
getContentPane().add(jButton1, new
org.netbeans.lib.awtextra.AbsoluteConstraints(660, 150, 90, 30));
jButton2.setText("Modificar");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
getContentPane().add(jButton2, new
org.netbeans.lib.awtextra.AbsoluteConstraints(660, 193, 90, 30));
jPanel1.setBackground(new java.awt.Color(255, 153, 153));
getContentPane().add(jPanel1, new
org.netbeans.lib.awtextra.AbsoluteConstraints(10, 0, 820, 500));
pack();
}// </editor-fold>
private void txt_nombreActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void txt_apepatActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void txt_apematActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void radio_mActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:

}
private void radio_fActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void radio_divActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void MusicaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void DeportesActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void computacionActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void ArtesActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void GuardarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
conexion= new ConexionDB();
Connection con=conexion.GetConnection();
Statement st;

nombre=txt_nombre.getText();
apellpat=txt_apepat.getText();
apellmat=txt_apemat.getText();
fecha = new
SimpleDateFormat("yyyy/MM/dd").format(DateChooser.getDate());
if (radio_m.isSelected()==true){
sexo="M";
}else if (radio_f.isSelected()==true){
sexo="F";
}
if (radio_sol.isSelected()==true){
edo="soltero";
}else if (radio_cas.isSelected()==true){
edo="casado";
}else if (radio_div.isSelected()==true){

edo="divorsiado";
}
educacion=(String)Educacion.getSelectedItem();
//
compu=computacion.isSelected();
deporte=Deportes.isSelected();
art=Artes.isSelected();
mus=Musica.isSelected();

// System.out.println(nombre +"\n"+
apellpat+"\n"+apellmat+"\n"+sexo+"\n"+edo+"\n"+educacion+"\n"+compu+"\
n"+deporte+"\n"+art+"\n"+mus+"\n"+fecha);
String sql="Insert into tbl_cliente
(nombre_cl,apepat_cl,apemat_cl,sexo_cl,edo_cl,educacion_cl,computacion_cl,de
portes_cl,arte_cl,musica_cl,Fecha)"
+"
values('"+nombre+"','"+apellpat+"','"+apellmat+"','"+sexo+"','"+edo+"','"+ed
ucacion+"',"+compu+","+deporte+","+art+","+mus+",'"+fecha+"')";

try{
st=con.createStatement();
st.executeUpdate(sql);
con.close();
st.close();
JOptionPane.showMessageDialog(null,"INSERTEADO CON EXITO");
}catch(SQLException e){
e.printStackTrace();
}
}
private void radio_solActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void ConsultarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
ConsultaDatos_1 ventana = new ConsultaDatos_1();
ventana.setVisible(true);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:

ConsultaDatos_1 elimina=new ConsultaDatos_1();


elimina.setVisible(true);
int id;
id=d.setText("");
tblEjemplo.rowAtPoint(e.getPoint());
String sql="delete tbl_cliente where id=('"+id+"')";
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
public void mouseClicked(MouseEvent e){
Alta_usr d= new Alta_usr();
//String id
=(String)tblEjemplo.getValueAt(tblEjemplo.getSelectedRow(),0);
//d.nombre.setText(id);
d.txt_nombre.setText("");
tblEjemplo.rowAtPoint(e.getPoint());
//d.txt_nombre.setText(tblEjemplo.getValueAt(row,0).toString);
}
});
}
}
/**
* @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(Alta_usr.class.getName()).log(java.util.logging
.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(Alta_usr.class.getName()).log(java.util.logging
.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Alta_usr.class.getName()).log(java.util.logging
.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Alta_usr.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 Alta_usr().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JCheckBox Artes;
private javax.swing.JButton Consultar;
private com.toedter.calendar.JDateChooser DateChooser;
private javax.swing.JCheckBox Deportes;
private javax.swing.JComboBox Educacion;
private javax.swing.JButton Guardar;
private javax.swing.JCheckBox Musica;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.ButtonGroup buttonGroup2;
private javax.swing.JCheckBox computacion;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
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;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JPanel jPanel1;
private javax.swing.JRadioButton radio_cas;
private javax.swing.JRadioButton radio_div;
private javax.swing.JRadioButton radio_f;
private javax.swing.JRadioButton radio_m;
private javax.swing.JRadioButton radio_sol;
private javax.swing.JTextField txt_apemat;
private javax.swing.JTextField txt_apepat;
public javax.swing.JTextField txt_nombre;

// End of variables declaration


}
package PuntodeVenta;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
/**
*
* @author Doris
*/
public class ConexionDB {
public static Connection GetConnection(){
Connection conexion=null;
try{
Class.forName("com.mysql.jdbc.Driver");
String servidor ="jdbc:mysql://localhost/puntoventa";
String usuarioDB="root";
String passwordDB="";

conexion=DriverManager.getConnection(servidor,usuarioDB,passwordDB);
}
catch (ClassNotFoundException ex){
JOptionPane.showMessageDialog(null, ex,"error en el driver",
JOptionPane.ERROR_MESSAGE);
conexion=null;
}
catch(SQLException ex){
JOptionPane.showMessageDialog(null, ex, "error en la conexion de
BD",JOptionPane.ERROR_MESSAGE);
conexion=null;
}catch(Exception ex){
JOptionPane.showMessageDialog(null,
ex,"error3",JOptionPane.ERROR_MESSAGE);
conexion=null;
}finally{
return conexion;
}
}

package PuntodeVenta;
import PuntodeVenta.ConexionDB;
import java.awt.event.MouseAdapter;

import
import
import
import
import
import
import
import
import

java.awt.event.MouseEvent;
java.sql.Connection;
java.sql.ResultSet;
java.sql.Statement;
javax.swing.JOptionPane;
javax.swing.JScrollPane;
javax.swing.JTable;
javax.swing.ListSelectionModel;
javax.swing.table.DefaultTableModel;

/**
*
* @author Doris
*/
public class ConsultaDatos_1 extends javax.swing.JFrame {
DefaultTableModel dtmEjemplo;
ListSelectionModel lsmConsultaDatos_1;
JTable tblEjemplo;
JScrollPane scpEjemplo;
public ConsultaDatos_1() {
tblEjemplo = new JTable();
scpEjemplo= new JScrollPane();
//Llenamos el modelo
dtmEjemplo = new DefaultTableModel(null,getColumnas());
setFilas();
tblEjemplo.setModel(dtmEjemplo);
scpEjemplo.add(tblEjemplo);
this.add(scpEjemplo);
this.setSize(800, 200);
scpEjemplo.setViewportView(tblEjemplo);

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
/********al dar clic pasar a cajas de texto**************/
tblEjemplo.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e){
Alta_usr d= new Alta_usr();
//String id
=(String)tblEjemplo.getValueAt(tblEjemplo.getSelectedRow(),0);
//d.nombre.setText(id);
d.txt_nombre.setText("");
tblEjemplo.rowAtPoint(e.getPoint());
//d.txt_nombre.setText(tblEjemplo.getValueAt(row,0).toString);
}

});
}
//Encabezados de la tabla
private String[] getColumnas()/// agregar los campos que hacen falta
{
String columna[]=new String[]{"Nombre","Apellido Paterno", "Apellido
Materno","sexo","estado","educacion","compuacion","deportes","arets","musica
","fecha_nac","ID"};
return columna;
}
private void setFilas()
{
ConexionDB conexion= new ConexionDB();
// Ejm12_1_ConectarPostgreSQL cnndb = new
Ejm12_1_ConectarPostgreSQL();
// CachedRowSet crs = conexion.Function("SELECT deptno, dname, loc
FROM dept");
Connection con=conexion.GetConnection();
Statement
st;
ResultSet
rs;
String sql="SELECT * FROM tbl_cliente";/// verificar latabla como se llama
Object datos[]=new Object[12];
//Numero de columnas de la tabla
///crresponde al numero de columnas de la BD
try {
st=con.createStatement();
rs=st.executeQuery(sql);
while (rs.next()) {
for (int i = 0; i < 12; i++) {/// revisar el ciclo for para revisar los
fregiatros de os datos
datos[i] = rs.getObject(i + 1);
}
dtmEjemplo.addRow(datos);
}
rs.close();
} catch (Exception e) {
}
}

/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always

* regenerated by the Form Editor.


*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton1.setText("jButton1");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton2.setText("MODIFICAR ");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addContainerGap(517, Short.MAX_VALUE)
.addComponent(jButton2)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addContainerGap(523, Short.MAX_VALUE)
.addComponent(jButton2)
.addContainerGap())
);
}// </editor-fold>
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int fila = tblEjemplo.getSelectedRow();
if (fila>=0) {
System.out.print("Se selecciona la fila numero: "+fila);
JOptionPane.showMessageDialog(null, "Exito");
}else{
JOptionPane.showMessageDialog(null , "SELECCIONE UNA FILA DE LA

TABLA ","ERROR",JOptionPane.ERROR_MESSAGE);
}
}
/**
* @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(ConsultaDatos.class.getName()).log(java.util.l
ogging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ConsultaDatos.class.getName()).log(java.util.l
ogging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ConsultaDatos.class.getName()).log(java.util.l
ogging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ConsultaDatos.class.getName()).log(java.util.l
ogging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ConsultaDatos_1().setVisible(true);
}
});
}

// Variables declaration - do not modify


private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
// End of variables declaration
}
}
package PuntodeVenta;
import java.sql.Connection;
import javax.swing.JOptionPane;
/**
*
* @author Doris
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Connection miConexion;
miConexion=ConexionDB.GetConnection();
if(miConexion!=null){
JOptionPane.showMessageDialog(null,"conexion realizada
correctamente");
}
}
}

Resultado
sy
observaci
ones

Conclusio
nes y/o
recomend
aciones

Referenci
as
bibliogrfi
cas y/o
Fuentes
consultad
as
Manejo y
Disposici
n de
Desechos:
Grup
o:
INI5M
A

Al concluir la prctica se adquirieron las habilidades para crear


interfaces como aplicaciones en el entorno de Java con ayuda del
JFrame y las opciones que nos ofrece para poder disear
completamente en una paleta la cual nos da una infinidad de
recursos que pueden ser utilizados de manera sencilla y si no se
cuenta con el recurso la forma ms prctica es importar este por
medio de una extensin o clase de archivo que nos brinde la
mayor comodidad como el Jcalendar
Java 2 interfaces grficas.

Equipo:

Calificaci
n:

Potrebbero piacerti anche