You are on page 1of 37

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

CRUD

NOMBRE DE LA UNIDAD DE APRENDIZAJE:

UNIDAD 4: INTERFACES GRAFICAS

FACILITADOR:
ING. LETICIA JAEL ROJAS ORTIZ
INTEGRANTES:
No
1

Matrcula
1314INI3
15

Nombre
BANDERA MORAN ROSARIO
GUADALUPE

Firma

MARZO, 2016

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

Duracin (horas)

COMPUTACION
Al concluir la unidad de aprendizaje el alumno ser capaz de
conocer las principales caractersticas de Java y de las diferentes
interfaces que pueden ser utilizadas en dicho lenguaje.

Marco
Terico:

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

Programacin Orientada a Objetos


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.
1 computadora
NetBeans

1 desarrollar la clase JFrame

Tambin tendremos que verificar si existe una conexin a base de


datos en la pestaa de servicios de los contrario se tendrn que
importar, tambin la de Jcalendar que ser ocupada
posteriormete.
2 en la parte de diseo realizar el diseo, agregando cajas de
texto, texto y radio botones para realizar nuestro diseo de forma
completa.

Cdigo
package PuntodeVenta;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import javax.swing.JOptionPane;
////// se incluyen las libreras que se requieren/////
/**
*
* @author Rosario
*/
public class Alta_usr extends javax.swing.JFrame {
//// se extiende la clase extends javax.swing.JFramepara
poder utilizar la interface///
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;
//// se declaran las variables///

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();
jPanel1 = new javax.swing.JPanel();
//// se cran los botones para su uso///

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, 110, 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,
30));
jPanel1.setBackground(new java.awt.Color(255, 51, 255));
jPanel1.setForeground(new java.awt.Color(255, 51, 204));
getContentPane().add(jPanel1, new
org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 780, 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:
}
/// son los votones que se deben modificar para su uso///
private void
GuardarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
conexion= new ConexionDB();
Connection con=conexion.GetConnection();
Statement st;
//// botn con el que se guarda las acciones
realizadas///
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();
/// se utilizan condiconales para la seleccin de las
opciones por parte del usuario//
// 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,com
putacion_cl,deportes_cl,arte_cl,musica_cl,Fecha)"
+"
values('"+nombre+"','"+apellpat+"','"+apellmat+"','"+sexo+"','"
+edo+"','"+educacion+"',"+compu+","+deporte+","+art+","+m
us+",'"+fecha+"')";
/// son los valores que se agregaran a la base de
datos///
try{
st=con.createStatement();
st.executeUpdate(sql);
con.close();
st.close();

JOptionPane.showMessageDialog(null,"INSERTEADO CON
EXITO");
}catch(SQLException e){
e.printStackTrace();
}
/// el Try y el Catch son para cumplir las excepciones
realizadas ///
}
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);
}
/// se realizan para realizar la consulta de los datos
insertados en la base de datos por el usuario, es decir
muestra datos que se requieren visualizar///
/**
* @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/pl
af.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(j
ava.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Alta_usr.class.getName()).log(j
ava.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Alta_usr.class.getName()).log(j
ava.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex)
{
java.util.logging.Logger.getLogger(Alta_usr.class.getName()).log(j
ava.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.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;
private javax.swing.JTextField txt_nombre;
// End of variables declaration
}
3 se realiz la conexin a base de datos

Cdigo
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 Rosario
*/
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="";
/// se crea la excepcin para realizar la conexin a
BD///
conexion=DriverManager.getConnection(servidor,usuarioDB,pass
wordDB);
}
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;
}
}
}
4 se crea un mtodo main para revisar si la conexin fue
exitosa

Cdigo
package PuntodeVenta;
import java.sql.Connection;
import javax.swing.JOptionPane;
/**
*
* @author Rosario
*/
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");
}
}
}
Creamos la base de Datos

Y realizamos un ingreso posteriormente el sistema ser


capaz de mostrar la consulta con el siguiente cdigo

}
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);
}
Eliminar:

Modificar:

Agregar:

Codigo:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package PuntodeVenta;
import
import
import
import
import

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

/**
*
* @author Rosario
*/
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
}

Resultado
sy
observaci
ones

Conclusio
nes y/o
recomend
aciones

Referenci
as
bibliogrfi
cas y/o
Fuentes
consultad
as

Al concluir la practica 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 mas practica es importar este por
medio de una extensin o clase de archivo que nos brinde la
mayor comodidad como el Jcalendar
Como Programar en Java 7 edicin
http://aprenderaprogramar.com/index.php?
option=com_content&view=article&id=644:concepto-odefinicion-de-interface-java-ique-es-una-interface-tipos-deinterfaz-ejemplo-practico-cu00677b&catid=68:curso-aprenderprogramacion-java-desde-cero&Itemid=188

Manejo y
Disposici
n de
Desechos:
Gru
po:

Equipo:

Bandera Moran Rosario


G.

Calificaci
n:

You might also like