jueves, 5 de marzo de 2009

Codigo Java N3: Carrito listadoJavaBeans.jsp

<%--
Document : listadoJavaBeans
Created on : 27/06/2008, 09:36:27 PM
Author : grosales
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
"http://www.w3.org/TR/html4/loose.dtd">

jsp:useBean id="sesion" class="pkgLogica.Sesion" scope="session"/
jsp:useBean id="listado" class="pkgLogica.Usuario" scope="page"/


Documento sin título




Bienvenido al sistema: <%= sesion.getTxt_nombre()%>








<%
java.util.Vector caja = listado.listado();
for (int contador=0; contador pkgLogica.Usuario u = (pkgLogica.Usuario)caja.get(contador);
%>







<%
}
%>
CODIGO CLAVE NOMBRE
">Modificar ">Eliminar <%= u.getCod_usuario()%> <%= u.getTxt_clave()%> <%= u.getTxt_nombre()%>


Codigo Java N3: Carrito listadoJSTL.jsp

<%-- Document : listadoJSTL.jsp Created on : 27/06/2008, 09:36:37 PM Author : grosales --%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
jsp:useBean id="listado" class="pkgLogica.Usuario" scope="page" /
<% pageContext.setAttribute("listado", listado.listado()); %>



JSP Page






c:forEach items="${listado}" var="lis1"





/c:forEach

LISTADO DE USUARIOS
CODIGOCLAVENOMBRE





Codigo Java N3: Carrito Usuario.java

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package pkgLogica;
import java.util.*;
/**
*
* @author windowsxp
*/
public class Usuario extends Conexion{
private String cod_usuario;
private String txt_clave;
private String txt_nombre;
//
Vector caja = new Vector();
//metodos
public boolean encUsuario(){
boolean existe = false;
try {
sql = "select * from tg_usuario where cod_usuario=? and txt_clave=?";
pstmt = cn.prepareStatement(sql);
pstmt.setString(1, cod_usuario);
pstmt.setString(2, txt_clave);
result = pstmt.executeQuery();
if (result.next()){
txt_nombre = result.getString("txt_nombre");
txt_clave = result.getString("txt_clave");
existe = true;
}
result.close();
pstmt.close();
cn.close();
} catch (Exception exception) {
System.out.println("Error = "+exception.getMessage());
}
return existe;
}
//Metod que sirve para insertar actualizar eliminar un usuario de la BD
public void insertUpdateDelete(int i){
try{
//inserta una nueva fila en la tabla tg_usuario
if (i==1){
sql = "insert into tg_usuario(cod_usuario,txt_nombre,txt_clave) values (?,?,?)";
pstmt = cn.prepareStatement(sql);
pstmt.setString(1,cod_usuario);
pstmt.setString(2,txt_nombre);
pstmt.setString(3,txt_clave);
//actualiza una fila en la tabla tg_usuario
}else if (i==2){
sql = "update tg_usuario set txt_nombre=?,txt_clave=? where cod_usuario=?";
pstmt = cn.prepareStatement(sql);
pstmt.setString(1,txt_nombre);
pstmt.setString(2,txt_clave);
pstmt.setString(3,cod_usuario);
//elimina una fila en la tabla tg_usuario
}else if (i==3){
sql = "delete from tg_usuario where cod_usuario=?";
pstmt=cn.prepareStatement(sql);
pstmt.setString(1,cod_usuario);
}
fila = pstmt.executeUpdate();
pstmt.close();
cn.close();
}catch(Exception e){
System.out.println("Error= "+e.getMessage());
}
}

public Vector listado(){
caja.removeAllElements();
try {
sql = "select * from tg_usuario";
pstmt = cn.prepareStatement(sql);
result = pstmt.executeQuery();
while (result.next()){
Usuario u = new Usuario();
u.setCod_usuario(result.getString("cod_usuario"));
u.setTxt_clave(result.getString("txt_clave"));
u.setTxt_nombre(result.getString("txt_nombre"));
caja.addElement(u);
}
result.close();
pstmt.close();
cn.close();
} catch (Exception exception) {
System.out.println("Error ="+exception.getMessage());
}
return caja;
}
public void registrar(){
try {
sql = "insert into tg_usuario(cod_usuario, txt_clave, txt_nombre) values(?,?,?)";
pstmt = cn.prepareStatement(sql);
pstmt.setString(1, cod_usuario);
pstmt.setString(2, txt_clave);
pstmt.setString(3, txt_nombre);
fila = pstmt.executeUpdate();
pstmt.close();
cn.close();
} catch (Exception exception) {
System.out.println(exception.getMessage());
}
}
public String getCod_usuario() {
return cod_usuario;
}

public void setCod_usuario(String cod_usuario) {
this.cod_usuario = cod_usuario;
}

public String getTxt_clave() {
return txt_clave;
}

public void setTxt_clave(String txt_clave) {
this.txt_clave = txt_clave;
}

public String getTxt_nombre() {
return txt_nombre;
}

public void setTxt_nombre(String txt_nombre) {
this.txt_nombre = txt_nombre;
}
}

Codigo Java N3: Carrito Sesion.java

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package pkgLogica;

/**
*
* @author grosales
*/
public class Sesion {
private String cod_usuario="";
private String txt_nombre="";

public String getCod_usuario() {
return cod_usuario;
}

public void setCod_usuario(String cod_usuario) {
this.cod_usuario = cod_usuario;
}

public String getTxt_nombre() {
return txt_nombre;
}

public void setTxt_nombre(String txt_nombre) {
this.txt_nombre = txt_nombre;
}
}

Codigo Java N3: Carrito Conexion.java

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package pkgLogica;
import java.sql.*;
/**
*
* @author grosales
*/
public class Conexion {
Connection cn = null;
PreparedStatement pstmt = null;
ResultSet result = null;
int fila = 0;
String sql = "";
//Constructor
public Conexion(){
try {
Class.forName("org.postgresql.Driver").newInstance();
System.out.println("Driver instalado");
//Para conectarse a la base de datos de clases
//cn = DriverManager.getConnection("jdbc:postgresql://172.16.3.77/portal_web","postgres","sistemas");
//Para conectarse a la base de datos local
cn = DriverManager.getConnection("jdbc:postgresql://localhost/portal_web","postgres","sistemas");
System.out.println("Base conectada");
} catch (Exception exception) {
System.out.println("Error::" + exception.getMessage());
}
}
}

Codigo Java N3: Carrito index.jsp

<%--
Document : index
Created on : 27/06/2008, 08:58:04 PM
Author : grosales
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
"http://www.w3.org/TR/html4/loose.dtd">



Documento sin título




















INGRESO AL SISTEMA
Usuario
Contraseña





Codigo Java N3: Carrito home.jsp

<%-- Document : home Created on : 27/06/2008, 09:17:41 PM Author : grosales --%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

jsp:usebean id="sesion" class="pkgLogica.Sesion" scope="session"


Documento sin título





Bienvenido al sistema: <%= sesion.getTxt_nombre()%>













MENU DE OPCIONES
Listado de usuarios con JavaBeans
Listado de usuarios con JSTL
Carrito de compras



miércoles, 4 de marzo de 2009

Codigo Java N3: Carrito conexion.jsp

<%--
Document : conexion
Created on : 27/06/2008, 09:08:56 PM
Author : grosales
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
"http://www.w3.org/TR/html4/loose.dtd">
jsp:useBean id="busqueda" class="pkgLogica.Usuario" scope="page"
jsp:setProperty name="busqueda" property="*" /
/jsp:useBean
<%
boolean existe = busqueda.encUsuario();
if (existe){
%>

jsp:useBean id="sesion" class="pkgLogica.Sesion" scope="session" /
jsp:setProperty name ="sesion" property="cod_usuario" value="<%= busqueda.getCod_usuario()%>" /
<%
sesion.setTxt_nombre(busqueda.getTxt_nombre());
response.sendRedirect("home.jsp");
}else{
response.sendRedirect("index.jsp");
}
%>

Codigo Java N2: WebOpera serOpera.java

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package operaciones;

import java.io.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;

/**
*
* @author Administrador
*/
public class serOpera extends HttpServlet {

/**
* Processes requests for both HTTP GET and POST methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
//Aqui comienza ell codigo ingresado
String genero = "";
double dblNumPeliculas = 0;
double dblPrecio = 0;
int intEsSocio = 0;
double dblTotal = 0;
String strEsSocio = "No";
try {
genero = request.getParameter("genero");
dblNumPeliculas = Double.parseDouble(request.getParameter("numPeliculas"));
dblPrecio = Double.parseDouble(request.getParameter("precio"));
intEsSocio = Integer.parseInt(request.getParameter("esSocio"));
//Otro modo
if (intEsSocio == 1){
dblTotal = dblNumPeliculas * dblPrecio;
strEsSocio = "Sí (20% de descuento)";
} else {
dblTotal = dblNumPeliculas * dblPrecio * 0.8;
}
//nuevo
request.setAttribute("genero", genero);
request.setAttribute("numPeliculas", String.valueOf(dblNumPeliculas));
request.setAttribute("total", String.valueOf(dblTotal));
request.setAttribute("esSocio", strEsSocio);
request.getRequestDispatcher("/respuesta.jsp").forward(request, response);
} finally {
out.close();
}
}

//
/**
* Handles the HTTP GET method.
* @param request servlet request
* @param response servlet response
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Handles the HTTP POST method.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Returns a short description of the servlet.
*/
public String getServletInfo() {
return "Short description";
}
//

}

Codigo Java N2: WebOpera respuesta.jsp

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>


"http://www.w3.org/TR/html4/loose.dtd">



JSP Page



























Género <%=request.getAttribute("genero")%>
Número de películas <%=request.getAttribute("numPeliculas")%>
Es socio <%=request.getAttribute("esSocio")%>
Total a pagar <%=request.getAttribute("total")%>
   




 



Codigo Java N2: WebOpera index.jsp

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>


"http://www.w3.org/TR/html4/loose.dtd">



JSP Page
























Genero
Precio unitario
Número de películas


Socio

No socio





Codigo Java N1: pryMenuTabla VenUsuario

/*
* venUsuario.java
*
* Created on 4 de mayo de 2008, 09:38 AM
*/

package prymenu;
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
/**
*
* @author Administrador
*/
public class VenUsuario extends javax.swing.JInternalFrame {
DefaultTableModel miModelo;
String[] cabecera={"Usuario","Clave","Nombre"};
String[][] datos={};
/** Creates new form venUsuario */
public VenUsuario() {
initComponents();
miModelo=new DefaultTableModel(datos,cabecera);
miTabla.setModel(miModelo);
mostrarTabla();
}

public void mostrarTabla(){
UsuarioBean usu=new UsuarioBean();
Vector caja=usu.listUsuario();
for(int i=0;i UsuarioBean u=(UsuarioBean)caja.get(i);
Object[] dato={
u.getCod_usuario(),
u.getTxt_clave(),
u.getTxt_nombre()
};
miModelo.addRow(dato);
}
}

public void borrarTabla(){
try{
int filas=miTabla.getRowCount();
do{
miModelo.removeRow(0);
filas--;
}while(filas>=0);
}catch(Exception e) {
System.out.println("Error= "+e.getMessage());
}
}

/** 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.
*/
//
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
miTabla = new javax.swing.JTable();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
txt_usuario = new javax.swing.JTextField();
txt_clave = new javax.swing.JTextField();
txt_nombre = new javax.swing.JTextField();
btn_agregar = new javax.swing.JButton();
btn_modificar = new javax.swing.JButton();
btn_grabar = new javax.swing.JButton();
btn_eliminar = new javax.swing.JButton();

setClosable(true);
setMaximizable(true);
setTitle("Ventana Usuario");
miTabla.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"
}
));
jScrollPane1.setViewportView(miTabla);

jLabel1.setFont(new java.awt.Font("Tahoma", 3, 11));
jLabel1.setText("USUARIO");

jLabel2.setFont(new java.awt.Font("Tahoma", 3, 11));
jLabel2.setText("CLAVE");

jLabel3.setFont(new java.awt.Font("Tahoma", 3, 11));
jLabel3.setText("NOMBRE");

btn_agregar.setText("AGREGAR");
btn_agregar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_agregarActionPerformed(evt);
}
});

btn_modificar.setText("MODIFICAR");
btn_modificar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_modificarActionPerformed(evt);
}
});

btn_grabar.setText("GRABAR");
btn_grabar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_grabarActionPerformed(evt);
}
});

btn_eliminar.setText("ELIMINAR");
btn_eliminar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_eliminarActionPerformed(evt);
}
});

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.TRAILING, false)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txt_nombre))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(txt_clave)
.addComponent(txt_usuario, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(btn_modificar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btn_agregar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btn_grabar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn_eliminar)))
.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(jLabel1)
.addComponent(txt_usuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn_agregar)
.addComponent(btn_eliminar))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(txt_clave, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn_modificar))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(txt_nombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn_grabar))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(19, Short.MAX_VALUE))
);
pack();
}//


private void btn_eliminarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int i;
int fila=miTabla.getSelectedRow();
if (fila<0){
JOptionPane.showMessageDialog(this,"Debe seleccionar una fila","Error",1);
}
else{
i = JOptionPane.showConfirmDialog(this, "¿Confirma que desea eliminar al usuario "
+ miModelo.getValueAt(fila,0).toString() + "?", "Alerta del sistema", 1);
if (i == 0){ //Respuesta Si
UsuarioBean u=new UsuarioBean();
u.setCod_usuario(miModelo.getValueAt(fila,0).toString());
u.setTxt_clave(miModelo.getValueAt(fila, 1).toString());
u.setTxt_nombre(miModelo.getValueAt(fila, 2).toString());
txt_usuario.setText("");
txt_clave.setText("");
txt_nombre.setText("");
u.eliminar();
borrarTabla();
mostrarTabla();
}
}
}

private void btn_modificarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int fila=miTabla.getSelectedRow();
if (fila<0){
JOptionPane.showMessageDialog(this,"Debe seleccionar una fila","Error",1);
}else{
txt_usuario.setText(miModelo.getValueAt(fila,0).toString());
txt_clave.setText(miModelo.getValueAt(fila, 1).toString());
txt_nombre.setText(miModelo.getValueAt(fila, 2).toString());
txt_usuario.setEditable(false);
//Botones
btn_agregar.setEnabled(false);
btn_eliminar.setEnabled(false);
miTabla.setEnabled(false);
}
}

private void btn_agregarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
UsuarioBean u=new UsuarioBean();
u.setCod_usuario(txt_usuario.getText());
u.setTxt_clave(txt_clave.getText());
u.setTxt_nombre(txt_nombre.getText());
u.registrar();
borrarTabla();
mostrarTabla();
//Limpiar campos
txt_usuario.setText("");
txt_clave.setText("");
txt_nombre.setText("");
}

private void btn_grabarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
UsuarioBean u=new UsuarioBean();
u.setCod_usuario(txt_usuario.getText());
u.setTxt_clave(txt_clave.getText());
u.setTxt_nombre(txt_nombre.getText());
u.modificar();
borrarTabla();
mostrarTabla();
txt_usuario.setText("");
txt_clave.setText("");
txt_nombre.setText("");
txt_usuario.setEditable(true);
//Botones
btn_agregar.setEnabled(true);
btn_eliminar.setEnabled(true);
miTabla.setEnabled(true);
}


// Variables declaration - do not modify
private javax.swing.JButton btn_agregar;
private javax.swing.JButton btn_eliminar;
private javax.swing.JButton btn_grabar;
private javax.swing.JButton btn_modificar;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable miTabla;
private javax.swing.JTextField txt_clave;
private javax.swing.JTextField txt_nombre;
private javax.swing.JTextField txt_usuario;
// End of variables declaration

}

Codigo Java N1: pryMenuTabla VenProducto

/*
* venUsuario.java
*
* Created on 4 de mayo de 2008, 09:38 AM
*/

package prymenu;
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
/**
*
* @author Administrador
*/
public class VenProducto extends javax.swing.JInternalFrame {
DefaultTableModel miModelo;
String[] cabecera={"Categoria","Codigo","Nombre"};
String[][] datos={};
/** Creates new form venUsuario */
public VenProducto() {
initComponents();
miModelo=new DefaultTableModel(datos,cabecera);
miTabla.setModel(miModelo);
mostrarTabla();
}

public void mostrarTabla(){
ProductoBean pro=new ProductoBean();
Vector caja=pro.listProducto();
for(int i=0;i ProductoBean u=(ProductoBean)caja.get(i);
Object[] dato={
u.getTxt_categoria(),
u.getTxt_codigo(),
u.getTxt_nombre()
};
miModelo.addRow(dato);
}
}

public void borrarTabla(){
try{
int filas=miTabla.getRowCount();
do{
miModelo.removeRow(0);
filas--;
}while(filas>=0);
}catch(Exception e) {
System.out.println("Error= "+e.getMessage());
}
}

/** 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.
*/
//
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
miTabla = new javax.swing.JTable();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
txt_producto = new javax.swing.JTextField();
txt_codigo = new javax.swing.JTextField();
btn_agregar = new javax.swing.JButton();
btn_modificar = new javax.swing.JButton();
btn_grabar = new javax.swing.JButton();
btn_eliminar = new javax.swing.JButton();
cbo_categoria = new javax.swing.JComboBox();

setClosable(true);
setMaximizable(true);
setTitle("Ventana Producto");
addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
formInternalFrameOpened(evt);
}
});

miTabla.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"
}
));
miTabla.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
miTablaVetoableChange(evt);
}
});

jScrollPane1.setViewportView(miTabla);

jLabel1.setFont(new java.awt.Font("Tahoma", 3, 11));
jLabel1.setText("PRODUCTO");

jLabel2.setFont(new java.awt.Font("Tahoma", 3, 11));
jLabel2.setText("CATEGORIA");

jLabel3.setFont(new java.awt.Font("Tahoma", 3, 11));
jLabel3.setText("CODIGO");

btn_agregar.setText("AGREGAR");
btn_agregar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_agregarActionPerformed(evt);
}
});

btn_modificar.setText("MODIFICAR");
btn_modificar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_modificarActionPerformed(evt);
}
});

btn_grabar.setText("GRABAR");
btn_grabar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_grabarActionPerformed(evt);
}
});

btn_eliminar.setText("ELIMINAR");
btn_eliminar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_eliminarActionPerformed(evt);
}
});

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)
.addGroup(layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 460, Short.MAX_VALUE)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3))
.addGap(14, 14, 14)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(txt_codigo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE)
.addComponent(txt_producto, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE)
.addComponent(cbo_categoria, javax.swing.GroupLayout.Alignment.LEADING, 0, 145, Short.MAX_VALUE))
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(btn_modificar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btn_agregar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btn_grabar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn_eliminar)
.addContainerGap(41, 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(jLabel1)
.addComponent(btn_agregar)
.addComponent(btn_eliminar)
.addComponent(txt_producto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(btn_modificar)
.addComponent(cbo_categoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(btn_grabar)
.addComponent(txt_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(27, Short.MAX_VALUE))
);
pack();
}//


private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
// TODO add your handling code here:
CategoriaBean pro = new CategoriaBean();
Vector lista = pro.listCategoria();
for(int i=0;i CategoriaBean u=(CategoriaBean)lista.get(i);
cbo_categoria.addItem(u.getTxt_nombre());
// Object[] dato={
// u.getCod_categoria(),
// u.getTxt_nombre()
// };
//cbo_categoria.addI
//cbo_categoria.addItem(dato);
}
}

private void miTablaVetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
// TODO add your handling code here:
}

private void btn_eliminarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int i;
int fila=miTabla.getSelectedRow();
if (fila<0){
JOptionPane.showMessageDialog(this,"Debe seleccionar una fila","Error",1);
}
else{
i = JOptionPane.showConfirmDialog(this, "¿Confirma que desea eliminar el producto con código "
+ miModelo.getValueAt(fila,1).toString() + "?", "Alerta del sistema", 1);
if (i == 0){ //Respuesta Si
ProductoBean u=new ProductoBean();
u.setCod_categoria(miModelo.getValueAt(fila,0).toString());
u.setTxt_codigo(miModelo.getValueAt(fila, 1).toString());
u.setTxt_nombre(miModelo.getValueAt(fila, 2).toString());
txt_producto.setText("");
cbo_categoria.setSelectedIndex(0);
txt_codigo.setText("");
u.eliminar();
borrarTabla();
mostrarTabla();
}
}
}

private void btn_modificarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int fila=miTabla.getSelectedRow();
if (fila<0){
JOptionPane.showMessageDialog(this,"Debe seleccionar una fila","Error",1);
}else{
txt_producto.setText(miModelo.getValueAt(fila,0).toString());
cbo_categoria.setSelectedItem(miModelo.getValueAt(fila,0).toString());
txt_codigo.setText(miModelo.getValueAt(fila, 2).toString());
//Botones
btn_agregar.setEnabled(false);
btn_eliminar.setEnabled(false);
miTabla.setEnabled(false);
}
}

private void btn_agregarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
ProductoBean u=new ProductoBean();
u.setCod_categoria(cbo_categoria.getSelectedIndex());
u.setTxt_codigo(txt_codigo.getText());
u.setTxt_nombre(txt_producto.getText());
u.registrar();
borrarTabla();
mostrarTabla();
//Limpiar campos
txt_producto.setText("");
cbo_categoria.setSelectedIndex(0);
txt_codigo.setText("");
}

private void btn_grabarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
ProductoBean u=new ProductoBean();
u.setCod_categoria(cbo_categoria.getSelectedIndex());
u.setTxt_codigo(txt_codigo.getText());
u.setTxt_nombre(txt_producto.getText());
u.modificar();
borrarTabla();
mostrarTabla();
txt_producto.setText("");
cbo_categoria.setSelectedIndex(0);
txt_codigo.setText("");
//Botones
btn_agregar.setEnabled(true);
btn_eliminar.setEnabled(true);
miTabla.setEnabled(true);
}


// Variables declaration - do not modify
private javax.swing.JButton btn_agregar;
private javax.swing.JButton btn_eliminar;
private javax.swing.JButton btn_grabar;
private javax.swing.JButton btn_modificar;
private javax.swing.JComboBox cbo_categoria;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable miTabla;
private javax.swing.JTextField txt_codigo;
private javax.swing.JTextField txt_producto;
// End of variables declaration

}

Codigo Java N1: pryMenuTabla UsuarioDao

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package prymenu;
import java.util.*;
/**
*
* @author Administrador
*/
public class UsuarioDao extends Conectar{
Vector caja=new Vector();

public void modificar(UsuarioBean o){
try{
sql="update tg_usuario set txt_clave='"+o.getTxt_clave()+"',"+
"txt_nombre='"+o.getTxt_nombre()+"'"+
" where cod_usuario='"+o.getCod_usuario()+"'";
stmt=cn.createStatement();
fila=stmt.executeUpdate(sql);
stmt.close();
}catch(Exception e){
System.out.println("Error= "+e.getMessage());
}
}

public void registrar(UsuarioBean o){
try{
sql="insert into tg_usuario(cod_usuario,txt_clave,txt_nombre) values ('"+o.getCod_usuario()+"',"+
"'"+o.getTxt_clave()+"','"+o.getTxt_nombre()+"')";
stmt=cn.createStatement();
fila=stmt.executeUpdate(sql);
stmt.close();
}catch(Exception e){
System.out.println("Error= "+e.getMessage());
}
}
//Eliminar
public void eliminar(UsuarioBean o){
try{
sql="delete from tg_usuario where cod_usuario = '" + o.getCod_usuario()
+ "'"; // and txt_clave = '" + o.getTxt_clave() + "'";

stmt=cn.createStatement();
fila=stmt.executeUpdate(sql);
stmt.close();
}catch(Exception e){
System.out.println("Error= "+e.getMessage());
}
}

public Vector listUsuario(){
caja.removeAllElements();
try{
sql="select * from tg_usuario order by cod_usuario";
stmt=cn.createStatement();
rs=stmt.executeQuery(sql);
while(rs.next()){
UsuarioBean u=new UsuarioBean();
u.setCod_usuario(rs.getString("cod_usuario"));
u.setTxt_clave(rs.getString("txt_clave"));
u.setTxt_nombre(rs.getString("txt_nombre"));
caja.addElement(u);
}
rs.close();
stmt.close();
}catch(Exception e){
System.out.println("Error= "+e.getMessage());
}
return caja;
}

public boolean encUsuario(UsuarioBean o){
boolean existe=false;
try{
sql="select * from tg_usuario where cod_usuario like '%"+o.getCod_usuario()+"%'" +
" and txt_clave like '%"+o.getTxt_clave()+"%'";
stmt=cn.createStatement();
rs=stmt.executeQuery(sql);
if (rs.next()){
o.setTxt_nombre(rs.getString("txt_nombre"));
existe=true;
}
rs.close();
stmt.close();
}catch(Exception e){
System.out.println("Error= "+e.getMessage());
}
return existe;
}

}

Codigo Java N1: pryMenuTabla UsuarioBean

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package prymenu;
import java.util.*;
/**
*
* @author Administrador
*/
public class UsuarioBean {
private String cod_usuario;
private String txt_clave;
private String txt_nombre;

public void registrar(){
UsuarioDao usu=new UsuarioDao();
usu.registrar(this);
}

public void modificar(){
UsuarioDao usu=new UsuarioDao();
usu.modificar(this);
}

public void eliminar(){
UsuarioDao usu=new UsuarioDao();
usu.eliminar(this);
}

public Vector listUsuario(){
UsuarioDao usu=new UsuarioDao();
return usu.listUsuario();
}

public boolean encUsuario(){
UsuarioDao usu=new UsuarioDao();
return usu.encUsuario(this);
}

public String getCod_usuario() {
return cod_usuario;
}

public void setCod_usuario(String cod_usuario) {
this.cod_usuario = cod_usuario;
}

public String getTxt_clave() {
return txt_clave;
}

public void setTxt_clave(String txt_clave) {
this.txt_clave = txt_clave;
}

public String getTxt_nombre() {
return txt_nombre;
}

public void setTxt_nombre(String txt_nombre) {
this.txt_nombre = txt_nombre;
}

}

Codigo Java N1: pryMenuTabla ProductoDao

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package prymenu;
import java.util.*;
import javax.swing.*;
/**
*
* @author Administrador
*/
public class ProductoDao extends Conectar{
Vector caja=new Vector();

public void modificar(ProductoBean o){
try{
sql="update tg_producto set cod_categoria='"+o.getCod_categoria()+"',"+
"cod_producto='"+o.getTxt_codigo()+"', txt_producto='"+o.getTxt_nombre()+
"' where cod_producto='"+o.getTxt_codigo()+"'";
stmt=cn.createStatement();
fila=stmt.executeUpdate(sql);
stmt.close();
}catch(Exception e){
System.out.println("Error= "+e.getMessage());
}
}

public void registrar(ProductoBean o){
try{
sql="insert into tg_producto (cod_categoria,cod_producto,txt_producto) values ('"+o.getCod_categoria()+"',"+
"'"+o.getTxt_codigo()+"','"+o.getTxt_nombre()+"')";
stmt=cn.createStatement();
fila=stmt.executeUpdate(sql);
stmt.close();
}catch(Exception e){
System.out.println("Error= "+e.getMessage());
}
}
//Eliminar
public void eliminar(ProductoBean o){
try{
sql="delete from tg_producto where cod_producto= '" + o.getTxt_codigo()
+ "'"; // and txt_clave = '" + o.getTxt_clave() + "'";
stmt=cn.createStatement();
fila=stmt.executeUpdate(sql);
stmt.close();
}catch(Exception e){
System.out.println("Error= "+e.getMessage());
}
}

public Vector listProducto(){
caja.removeAllElements();
try{
sql="select a.txt_categoria as cate, b.cod_producto as prod, b.txt_producto as nom, b.cod_categoria as cate2"
+ " from tg_producto b left join tg_categoria a on b.cod_categoria = a.cod_categoria"
+ " order by cod_producto";
System.out.println("Cons= "+sql);
stmt=cn.createStatement();
rs=stmt.executeQuery(sql);
while(rs.next()){
ProductoBean u=new ProductoBean();
u.setTxt_categoria(rs.getString("cate"));
u.setTxt_codigo(rs.getString("prod"));
u.setTxt_nombre(rs.getString("nom"));
u.setCod_categoria(rs.getString("cate2"));
caja.addElement(u);
}
rs.close();
stmt.close();
}catch(Exception e){
System.out.println("Error= "+e.getMessage());
}
return caja;
}

public boolean encProducto(ProductoBean o){
boolean existe=false;
try{
sql="select * from tg_producto where cod_producto like '%"+o.getTxt_codigo()+"%'" +
" and txt_producto like '%"+o.getTxt_nombre()+"%'";
stmt=cn.createStatement();
rs=stmt.executeQuery(sql);
if (rs.next()){
o.setTxt_nombre(rs.getString("txt_producto"));
existe=true;
}
rs.close();
stmt.close();
}catch(Exception e){
System.out.println("Error= "+e.getMessage());
}
return existe;
}

}

Codigo Java N1: pryMenuTabla ProductoBean

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package prymenu;
import java.util.*;
/**
*
* @author Administrador
*/
public class ProductoBean {
private String cod_categoria;
private String txt_codigo;
private String txt_nombre;
private String txt_categoria;

public void registrar(){
ProductoDao pro=new ProductoDao();
pro.registrar(this);
}

public void modificar(){
ProductoDao pro=new ProductoDao();
pro.modificar(this);
}

public void eliminar(){
ProductoDao pro=new ProductoDao();
pro.eliminar(this);
}

public Vector listProducto(){
ProductoDao pro=new ProductoDao();
return pro.listProducto();
}

public boolean encProducto(){
ProductoDao pro=new ProductoDao();
return pro.encProducto(this);
}

public String getCod_categoria() {
return cod_categoria;
}

public void setCod_categoria(String cod_categoria) {
this.cod_categoria = cod_categoria;
}

public String getTxt_codigo() {
return txt_codigo;
}

public void setTxt_codigo(String txt_codigo) {
this.txt_codigo = txt_codigo;
}

public String getTxt_nombre() {
return txt_nombre;
}

public void setTxt_nombre(String txt_nombre) {
this.txt_nombre = txt_nombre;
}

void setCod_categoria(Integer i) {
this.cod_categoria = i.toString();
}

public String getTxt_categoria() {
return txt_categoria;
}

public void setTxt_categoria(String txt_categoria) {
this.txt_categoria = txt_categoria;
}

}

Codigo Java N1: pryMenuTabla Principal.java

/*
* Principal.java
*
* Created on 4 de mayo de 2008, 09:10 AM
*/

package prymenu;

/**
*
* @author Administrador
*/
public class Principal extends javax.swing.JFrame {
static String txt_nombre="";
VenUsuario venUsuario=new VenUsuario();
VenProducto venProducto=new VenProducto();
/** Creates new form Principal */
public Principal(String nom) {
initComponents();
txt_nombre=nom;
setTitle("Sistema Usuario - Bienvenido : "+txt_nombre);
}

/** 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.
*/
//
private void initComponents() {
jDesktopPane1 = new javax.swing.JDesktopPane();
Menu = new javax.swing.JMenuBar();
mTabla = new javax.swing.JMenu();
mtUsuario = new javax.swing.JMenuItem();
mtProducto = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

mTabla.setText("Tabla");
mtUsuario.setText("Usuario");
mtUsuario.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mtUsuarioActionPerformed(evt);
}
});

mTabla.add(mtUsuario);

mtProducto.setText("Producto");
mtProducto.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mtProductoActionPerformed(evt);
}
});

mTabla.add(mtProducto);

Menu.add(mTabla);

jMenu2.setText("Edit");
Menu.add(jMenu2);

setJMenuBar(Menu);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jDesktopPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE)
);
pack();
}//


private void mtProductoActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(venProducto.isVisible()){
venProducto.moveToFront();
}else{
jDesktopPane1.add(venProducto);
venProducto.setVisible(true);
venProducto.moveToFront();
}

}

private void mtUsuarioActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(venUsuario.isVisible()){
venUsuario.moveToFront();
}else{
jDesktopPane1.add(venUsuario);
venUsuario.setVisible(true);
venUsuario.moveToFront();
}
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Principal("").setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JMenuBar Menu;
private javax.swing.JDesktopPane jDesktopPane1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenu mTabla;
private javax.swing.JMenuItem mtProducto;
private javax.swing.JMenuItem mtUsuario;
// End of variables declaration

}

Codigo Java N1: pryMenuTabla Conectar

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package prymenu;
import java.sql.*;
/**
*
* @author Administrador
*/
public class Conectar {
Connection cn=null;
Statement stmt=null;
ResultSet rs=null;
int fila=0;
String sql="";

public Conectar(){
try{
Class.forName("org.postgresql.Driver").newInstance();
System.out.println("Driver instalado");
cn=DriverManager.getConnection("jdbc:postgresql://localhost/PORTAL_WEB","postgres","sistemas");
System.out.println("Base conectada");
}catch(Exception e){
System.out.println("Error= "+e.getMessage());
}
}

}

Codigo Java N1: pryMenuTabla CategoriaDao

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package prymenu;
import java.util.*;
/**
*
* @author Administrador
*/
public class CategoriaDao extends Conectar{
Vector lista=new Vector();

public Vector listCategoria(){
lista.removeAllElements();
try{
sql="select * from tg_categoria order by cod_categoria";
stmt=cn.createStatement();
rs=stmt.executeQuery(sql);
while(rs.next()){
CategoriaBean u=new CategoriaBean();
u.setCod_categoria(rs.getString("cod_categoria"));
u.setTxt_nombre(rs.getString("txt_categoria"));
lista.addElement(u);
}
rs.close();
stmt.close();
}catch(Exception e){
System.out.println("Error= "+e.getMessage());
}
return lista;
}
}

Codigo Java N1: pryMenuTabla CategoriaBean

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package prymenu;
import java.util.*;
/**
*
* @author Administrador
*/
public class CategoriaBean {
private String cod_categoria;
private String txt_nombre;

public Vector listCategoria(){
CategoriaDao cat=new CategoriaDao();
return cat.listCategoria();
}

public String getCod_categoria() {
return cod_categoria;
}

public void setCod_categoria(String cod_categoria) {
this.cod_categoria = cod_categoria;
}

public String getTxt_nombre() {
return txt_nombre;
}

public void setTxt_nombre(String txt_nombre) {
this.txt_nombre = txt_nombre;
}
}

Codigo Java N1: pryMenuTabla Acceso.java

/*
* Acceso.java
*
* Created on 4 de mayo de 2008, 08:28 AM
*/

package prymenu;

import javax.swing.JOptionPane;

/**
*
* @author Administrador
*/
public class Acceso extends javax.swing.JFrame {

/** Creates new form Acceso */
public Acceso() {
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.
*/
//
private void initComponents() {

jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
txt_usuario = new javax.swing.JTextField();
txt_clave = new javax.swing.JPasswordField();
btn_aceptar = new javax.swing.JButton();
btn_salir = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
jLabel1.setText("ACCESO AL SISTEMA");

jLabel2.setText("USUARIO");

jLabel3.setText("CLAVE");

btn_aceptar.setText("ACEPTAR");
btn_aceptar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_aceptarActionPerformed(evt);
}
});

btn_salir.setText("SALIR");
btn_salir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_salirActionPerformed(evt);
}
});

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(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(btn_aceptar)
.addGap(18, 18, 18)
.addComponent(btn_salir))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txt_usuario))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(jLabel3)
.addGap(18, 18, 18)
.addComponent(txt_clave, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(txt_usuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(txt_clave, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btn_aceptar)
.addComponent(btn_salir))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

pack();
}//


private void btn_salirActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(0);
}

private void btn_aceptarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
UsuarioBean u=new UsuarioBean();
u.setCod_usuario(txt_usuario.getText());
u.setTxt_clave(String.copyValueOf(txt_clave.getPassword()));
if (u.encUsuario()){
Principal p=new Principal(u.getTxt_nombre());
p.setVisible(true);
this.dispose();
}else{
JOptionPane.showMessageDialog(this,"Usuario y/o Clave no es correcto");
txt_clave.setText("");
txt_usuario.setText("");
txt_usuario.requestFocus();
}
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Acceso().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JButton btn_aceptar;
private javax.swing.JButton btn_salir;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPasswordField txt_clave;
private javax.swing.JTextField txt_usuario;
// End of variables declaration

}