Buscar
Social
Ofertas laborales ES

Foro sobre Java SE > AYUDA CON CODIGO

TENGO UN PROBLEMA , TENGO UN EVENTO QUE LE DAS CLICK EN EL JTABLE Y LO MANDA LOS CAMPOS ALOS TXTFIELD Y JCOMBO PERO SI POGO DOS JCOMBO SEGUIDOS NO ME LEE EL 2DO,

LES DEJO EL CODIGO

package Vistas;

import Data.Conexion0;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;


public class frArticulos extends javax.swing.JInternalFrame {

static Connection conn=null;
static Statement st=null;
static ResultSet rs3=null;//Articulos
static ResultSet rs=null;//Lineas
static ResultSet rs1=null;//Marcas
static ResultSet rs31=null;//Unidad de Medida

String mar,lin,uni1,uni2;
DefaultTableModel dtm=new DefaultTableModel();

int fila=-1;

public frArticulos() {
initComponents();
setResizable(false);
setIconifiable(false);
setClosable(false);
setMaximizable(false);
setTitle("Articulos");
setSize(650,450);


String titulos[]={"Codigo"," Nombre o Descripcion ","Marca","Linea","Precio"};
dtm.setColumnIdentifiers(titulos);
tablaArticulos.setModel(dtm);



try
{

conn=Conexion0.Enlace(conn);

rs1=Conexion0.EnlMar(rs1);
rs31=Conexion0.EnlMaeUni(rs31);
rs=Conexion0.EnLMaeLin(rs);
rs3=Conexion0.EnlArt(rs3);

while(rs1.next())
{
cboCodMar.addItem((String)rs1.getString(1));
}


while(rs.next())
{
cboCodLin.addItem((String)rs.getString(1));
}

while(rs31.next())
{
cbocoduni1.addItem((String)rs31.getString(1));
cbocoduni2.addItem((String)rs31.getString(1));

}


}
catch(SQLException e)
{
JOptionPane.showMessageDialog(null,"Error "+e.getMessage());
}
desactiva();
limpiarObjetos();
listar();
}

public void desactiva()
{
txtcodart.setEnabled(false);
txtnomart.setEnabled(false);
cboCodMar.setEnabled(false);
cboCodLin.setEnabled(false);
cbocoduni1.setEnabled(false);
txtfac.setEnabled(false);
cbocoduni2.setEnabled(false);
txtsku.setEnabled(false);
txtpremin.setEnabled(false);
txtpremax.setEnabled(false);
txtcodvta.setEnabled(false);
}

public void limpiarObjetos()
{
txtcodart.setText("");
txtnomart.setText("");
cboCodMar.setSelectedIndex(-1);
cboCodLin.setSelectedIndex(-1);
cbocoduni1.setSelectedIndex(-1);
txtfac.setText("");
cbocoduni2.setSelectedIndex(-1);
txtsku.setText("");
txtpremin.setText("");
txtpremax.setText("");
txtcodvta.setText("");
txtmarnom.setText("");
txtlinnom.setText("");
txtnomuni1.setText("");
txtnomuni2.setText("");
}

public void activaBotones(boolean n, boolean m, boolean g,boolean h)
{
btnNuevo.setEnabled(n);
btnEliminar.setEnabled(m);
btnModificar.setEnabled(g);
btnGrabar.setEnabled(h);

}
public void listar()
{
try
{
int f,i;
conn=Conexion0.Enlace(conn);
rs3=Conexion0.EnlArt(rs3);
String datos[]=new String[5];
f=dtm.getRowCount();
if(f>0)
for(i=0;i<f;i++)
dtm.removeRow(0);
while(rs3.next())
{
datos[0]=(String)rs3.getString(1);
datos[1]=(String)rs3.getString(2);
datos[2]=(String)rs3.getString(3);
datos[3]=(String)rs3.getString(4);
datos[4]=(String)rs3.getString(5);
dtm.addRow(datos);
}

}
catch(SQLException e)
{
JOptionPane.showMessageDialog(null,"Error"+e.getMessage());
}

}

public void deleteArticulos()
{
try
{
conn=Conexion0.Enlace(conn);
st=Conexion0.sta(st);
rs3=Conexion0.EnlArt(rs3);
int cod;
cod=Integer.parseInt(txtcodart.getText());
PreparedStatement pstmt=conn.prepareStatement("{call sp_eliminaArticulo(?)}");
pstmt.setInt(1,cod);
pstmt.executeUpdate();
conn.close();
}
catch(SQLException e)
{
JOptionPane.showMessageDialog(null,"Error "+e.toString());
}
}
//////////////////////////////////////////////////////
public void updateArticulos()
{
try
{
conn=Conexion0.Enlace(conn);
st=Conexion0.sta(st);
rs3=Conexion0.EnlArt(rs3);
String nom,mar,lin,sku,min,max,un1,un2,vta,fac;

int cod;
cod=Integer.parseInt(txtcodart.getText());
nom=txtnomart.getText();
mar=(String)cboCodMar.getSelectedItem();
lin=(String)cboCodLin.getSelectedItem();
sku=txtsku.getText();
min=txtpremin.getText();
max=txtpremax.getText();
un1=(String)cbocoduni1.getSelectedItem();
un2=(String)cbocoduni2.getSelectedItem();
vta=txtcodvta.getText();
fac=txtfac.getText();



PreparedStatement pstmt=conn.prepareStatement("{call "
+ "sp_modificarArt(?,?,?,?,?,?,?,?,?,?,?)}");
pstmt.setInt(1, cod);
pstmt.setString(2,nom);
pstmt.setString(3,mar);
pstmt.setString(4,lin);
pstmt.setString(5,sku);
pstmt.setString(6,min);
pstmt.setString(7,max);
pstmt.setString(8,un1);
pstmt.setString(9,un2);
pstmt.setString(10,vta);
pstmt.setString(11,fac);

pstmt.executeUpdate();
conn.close();

listar();
limpiarObjetos();
}

catch(SQLException e)
{
JOptionPane.showMessageDialog(null,"Error "+e.toString());

}
}
////////////////////////////////////////////////////////////////


public void newArticulos()
{
try
{
conn=Conexion0.Enlace(conn);
st=Conexion0.sta(st);
rs3=Conexion0.EnlArt(rs3);


String nom,mar,lin,sku,min,max,un1,un2,vta,fac;

int cod;
cod=Integer.parseInt(txtcodart.getText());
nom=txtnomart.getText();
mar=(String)cboCodMar.getSelectedItem();
lin=(String)cboCodLin.getSelectedItem();
sku=txtsku.getText();
min=txtpremin.getText();
max=txtpremax.getText();
un1=(String)cbocoduni1.getSelectedItem();
un2=(String)cbocoduni2.getSelectedItem();
vta=txtcodvta.getText();
fac=txtfac.getText();

PreparedStatement pstmt=conn.prepareStatement("{call "
+ "sp_grabaArticulo(?,?,?,?,?,?,?,?,?,?,?)}");
pstmt.setInt(1, cod);
pstmt.setString(2,nom);
pstmt.setString(3,mar);
pstmt.setString(4,lin);
pstmt.setString(5,sku);
pstmt.setString(6,min);
pstmt.setString(7,max);
pstmt.setString(8,un1);
pstmt.setString(9,un2);
pstmt.setString(10,vta);
pstmt.setString(11,fac);


pstmt.executeUpdate();
conn.close();

listar();
limpiarObjetos();
}
catch(SQLException e)
{
JOptionPane.showMessageDialog(null,"Error en Datos "+e.toString());
}
}
////////////////////////////////////////////////////////////////

public void seleccionaFila()
{
if (fila > -1)
{
txtcodart.setText(String.valueOf(tablaArticulos.getValueAt(fila,0)));
txtnomart.setText(String.valueOf(tablaArticulos.getValueAt(fila,1)));
cboCodMar.setSelectedItem(String.valueOf(tablaArticulos.getValueAt(fila,2)));
cboCodLin.setSelectedItem(String.valueOf(tablaArticulos.getValueAt(fila,3)));
txtpremax.setText(String.valueOf(tablaArticulos.getValueAt(fila,4)));


}


}
//////////////////////////////////////////

public void validarCod()
{
String id= txtcodart.getText();
Boolean av=false;

for(int i=0;i<tablaArticulos.getRowCount();i++)
{
if(tablaArticulos.getValueAt(i,0).equals(id))
{
JOptionPane.showMessageDialog(null,"El Codigo"+id
+"ya existe en la tabla");
av=true;
limpiarObjetos();
}
}
if(av==false)
{
newArticulos();
}
}


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

jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
txtfac = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
txtnomart = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
txtcodart = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
txtpremax = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
cbocoduni1 = new javax.swing.JComboBox();
cboCodMar = new javax.swing.JComboBox();
cboCodLin = new javax.swing.JComboBox();
jLabel6 = new javax.swing.JLabel();
cbocoduni2 = new javax.swing.JComboBox();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
txtpremin = new javax.swing.JTextField();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
txtsku = new javax.swing.JTextField();
jLabel11 = new javax.swing.JLabel();
txtcodvta = new javax.swing.JTextField();
txtmarnom = new javax.swing.JTextField();
txtlinnom = new javax.swing.JTextField();
txtnomuni1 = new javax.swing.JTextField();
txtnomuni2 = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
tablaArticulos = new javax.swing.JTable();
btnNuevo = new javax.swing.JButton();
btnModificar = new javax.swing.JButton();
btnEliminar = new javax.swing.JButton();
btnGrabar = new javax.swing.JButton();
btnCancelar = new javax.swing.JButton();
btnSalir = new javax.swing.JButton();

jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos Generales", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1, 12))); // NOI18N

jLabel1.setText("Codigo :");

txtfac.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.red, null));

jLabel2.setText("Nombre o Descripcion :");

txtnomart.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.red, null));

jLabel3.setText("Marca :");

txtcodart.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.red, null));

jLabel4.setText("Linea :");

txtpremax.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.red, null));

jLabel5.setText("Unidad 1 :");

cbocoduni1.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.red, null));
cbocoduni1.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
cbocoduni1ItemStateChanged(evt);
}
});

cboCodMar.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.red, null));
cboCodMar.setOpaque(false);
cboCodMar.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
cboCodMarItemStateChanged(evt);
}
});

cboCodLin.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.red, null));
cboCodLin.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
cboCodLinItemStateChanged(evt);
}
});

jLabel6.setText("Factor :");

cbocoduni2.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.red, null));
cbocoduni2.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
cbocoduni2ItemStateChanged(evt);
}
});

jLabel7.setText("Unidad 2 :");

jLabel8.setText("Precio Max :");

txtpremin.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.red, null));

jLabel9.setText("Precio Min. :");

jLabel10.setText("SKU :");

txtsku.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.red, null));

jLabel11.setText("Cod .Vta. :");

txtcodvta.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.red, null));

txtmarnom.setEditable(false);
txtmarnom.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.red, null));

txtlinnom.setEditable(false);
txtlinnom.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.red, null));

txtnomuni1.setEditable(false);
txtnomuni1.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.red, null));
txtnomuni1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

txtnomuni2.setEditable(false);
txtnomuni2.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.red, null));

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(txtcodart, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 70, Short.MAX_VALUE)
.addComponent(jLabel11)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtcodvta, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(txtnomart, javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(cboCodLin, 0, 60, Short.MAX_VALUE)
.addComponent(cboCodMar, 0, 60, Short.MAX_VALUE)
.addComponent(txtsku, javax.swing.GroupLayout.Alignment.LEADING))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(0, 52, Short.MAX_VALUE)
.addComponent(jLabel9)
.addGap(12, 12, 12)
.addComponent(txtpremin, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(txtmarnom)
.addComponent(txtlinnom))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING))
.addGap(2, 2, 2)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(txtpremax)
.addComponent(cbocoduni2, 0, 60, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtnomuni2, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(cbocoduni1, javax.swing.GroupLayout.Alignment.LEADING, 0, 60, Short.MAX_VALUE)
.addComponent(txtfac, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtnomuni1)))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(104, 104, 104)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cbocoduni2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtnomuni2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtcodart, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtcodvta, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel11))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtnomart, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2)
.addComponent(jLabel5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cboCodMar, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cboCodLin, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4)
.addComponent(txtlinnom, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtsku, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel10)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGap(62, 62, 62)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtmarnom, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6)
.addComponent(txtfac, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(37, 37, 37)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtpremin, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel9)
.addComponent(jLabel8)
.addComponent(txtpremax, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cbocoduni1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtnomuni1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(93, 93, 93)))
.addContainerGap())
);

tablaArticulos.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0)));
tablaArticulos.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {

},
new String [] {

}
));
tablaArticulos.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
tablaArticulosMouseClicked(evt);
}
});
jScrollPane1.setViewportView(tablaArticulos);

btnNuevo.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
btnNuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/botones/nuevo.jpg"))); // NOI18N
btnNuevo.setText("Nuevo");
btnNuevo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnNuevoActionPerformed(evt);
}
});

btnModificar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
btnModificar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/botones/modificar.png"))); // NOI18N
btnModificar.setText("Modificar");
btnModificar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnModificarActionPerformed(evt);
}
});

btnEliminar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
btnEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/botones/eliminar.png"))); // NOI18N
btnEliminar.setText("Eliminar");
btnEliminar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnEliminarActionPerformed(evt);
}
});

btnGrabar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
btnGrabar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/botones/guardar.png"))); // NOI18N
btnGrabar.setText("Guardar");
btnGrabar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnGrabarActionPerformed(evt);
}
});

btnCancelar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/botones/cancelar.png"))); // NOI18N
btnCancelar.setText("Cancelar");
btnCancelar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCancelarActionPerformed(evt);
}
});

btnSalir.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
btnSalir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/botones/salir.gif"))); // NOI18N
btnSalir.setText("Salir");
btnSalir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSalirActionPerformed(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)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(btnNuevo)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnModificar)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnEliminar)
.addGap(10, 10, 10)
.addComponent(btnGrabar)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCancelar)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnSalir)
.addGap(0, 36, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, 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, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnNuevo)
.addComponent(btnModificar)
.addComponent(btnEliminar)
.addComponent(btnGrabar)
.addComponent(btnSalir)
.addComponent(btnCancelar))
.addContainerGap())
);

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

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

limpiarObjetos();
btnNuevo.setText("grabar");
txtcodart.setEnabled(true);
txtnomart.setEnabled(true);
cboCodMar.setEnabled(true);
cboCodLin.setEnabled(true);
txtmarnom.setEnabled(false);
txtlinnom.setEnabled(false);
txtsku.setEnabled(true);
txtpremin.setEnabled(true);
txtpremax.setEnabled(true);
txtcodvta.setEnabled(true);
cbocoduni1.setEnabled(true);
cbocoduni2.setEnabled(true);
txtnomuni1.setEnabled(false);
txtnomuni2.setEnabled(false);
txtfac.setEnabled(true);
txtcodart.requestFocus();
btnGrabar.setEnabled(true);
limpiarObjetos();
activaBotones(false,false,false,true);

}

private void btnModificarActionPerformed(java.awt.event.ActionEvent evt) {
int resp;
resp=JOptionPane.showConfirmDialog(null,"¿Desea Modificar los Datos?","Pregunta",0);

if(resp==JOptionPane.YES_OPTION)
{
int cod;
cod=Integer.parseInt(txtcodart.getText());

if(fila==-1)
{
JOptionPane.showMessageDialog(null,"Ninguna Fila Seleccionada");
btnModificar.setText("Modificar");
txtcodart.setEnabled(false);
//txtnommar.setEnabled(false);
activaBotones(true,true,true,false);

}

btnModificar.setText("grabar");
seleccionaFila();
txtcodart.setEnabled(true);
txtnomart.setEnabled(true);
cboCodMar.setEnabled(true);
cboCodLin.setEnabled(true);
txtmarnom.setEnabled(false);
txtlinnom.setEnabled(false);
txtsku.setEnabled(true);
txtpremin.setEnabled(true);
txtpremax.setEnabled(true);
txtcodvta.setEnabled(true);
cbocoduni1.setEnabled(true);
cbocoduni2.setEnabled(true);
txtnomuni1.setEnabled(false);
txtnomuni2.setEnabled(false);
txtfac.setEnabled(true);
txtcodart.requestFocus();

listar();
activaBotones(false,true,false,true);
}

}

private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {
int resp;
resp=JOptionPane.showConfirmDialog(null,"¿Desea Eliminar el Registro?","Pregunta",0);
if(resp==0)
{
if (fila > -1)
{

deleteArticulos();
listar();
activaBotones(true,true,true,false);
limpiarObjetos();
fila=-1; }
}
}

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

int resp;
resp=JOptionPane.showConfirmDialog(null,"¿Desea Grabar el Registro?","Pregunta",0);
if(resp==0)
{
if(btnModificar.getText().compareTo("grabar")==0)
{

updateArticulos();
btnModificar.setText("Modificar");
activaBotones(true,true,true,false);

}

if(btnNuevo.getText().compareTo("grabar")==0)
{
validarCod();

btnNuevo.setText("Nuevo");
activaBotones(true,true,true,false);
}
desactiva();
}
}

private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {
int resp;
resp=JOptionPane.showConfirmDialog(null,"¿Deseas Cancelar el Proceso?", "Pregunta",0);
if(resp==0)
{

limpiarObjetos();
desactiva();
activaBotones(true,true,true,false);
}
}

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

int resp;
resp=JOptionPane.showConfirmDialog(null,"¿Deseas Salir del Proceso?", "Pregunta",0);
if(resp==0)
{

limpiarObjetos();

dispose();
}
}

private void cboCodMarItemStateChanged(java.awt.event.ItemEvent evt) {

int posicion=cboCodMar.getSelectedIndex();


try
{
mar=Conexion0.LeerMarca(posicion).getMarnom();
this.txtmarnom.setText(""+mar);


}
catch(Exception ex)
{

}
}

private void cboCodLinItemStateChanged(java.awt.event.ItemEvent evt) {

int posicion=cboCodLin.getSelectedIndex();


try
{
lin=Conexion0.LeerLin(posicion).getLinnom();
this.txtlinnom.setText(""+lin);


}
catch(Exception ex)
{

}
}

private void cbocoduni2ItemStateChanged(java.awt.event.ItemEvent evt) {

int posicion=cbocoduni2.getSelectedIndex();


try
{
uni2=Conexion0.LeerUni(posicion).getUninom();
this.txtnomuni2.setText(""+uni2);


}
catch(Exception ex)
{

}
}

private void cbocoduni1ItemStateChanged(java.awt.event.ItemEvent evt) {

int posicion=cbocoduni1.getSelectedIndex();


try
{
uni1=Conexion0.LeerUni(posicion).getUninom();
this.txtnomuni1.setText(""+uni1);


}
catch(Exception ex)
{

}
}

private void tablaArticulosMouseClicked(java.awt.event.MouseEvent evt) {
fila = tablaArticulos.rowAtPoint(evt.getPoint());
limpiarObjetos();

seleccionaFila();
}


// Variables declaration - do not modify
private javax.swing.JButton btnCancelar;
private javax.swing.JButton btnEliminar;
private javax.swing.JButton btnGrabar;
private javax.swing.JButton btnModificar;
private javax.swing.JButton btnNuevo;
private javax.swing.JButton btnSalir;
private javax.swing.JComboBox cboCodLin;
private javax.swing.JComboBox cboCodMar;
private javax.swing.JComboBox cbocoduni1;
private javax.swing.JComboBox cbocoduni2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
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.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable tablaArticulos;
private javax.swing.JTextField txtcodart;
private javax.swing.JTextField txtcodvta;
private javax.swing.JTextField txtfac;
private javax.swing.JTextField txtlinnom;
private javax.swing.JTextField txtmarnom;
private javax.swing.JTextField txtnomart;
private javax.swing.JTextField txtnomuni1;
private javax.swing.JTextField txtnomuni2;
private javax.swing.JTextField txtpremax;
private javax.swing.JTextField txtpremin;
private javax.swing.JTextField txtsku;
// End of variables declaration
}

octubre 19, 2015 | Unregistered CommenterMIGUEL

No das ninguna pista del evento que te falla, ni de por qué, y nos plantas un código muy largo que, encima, en este sitio web resulta difícil de leer (esto último no es culpa tuya).

¿Puedes dar más detalles? ¿O, mejor aún, intenta preparar un SSCCE (Short Self-Contained Code Example)? Un SSCCE es un ejemplo lo más pequeño posible que, en el caso de usarlo para pedir ayuda, contenga el problema por el que preguntas. Lleva más tiempo pero, a menudo, ayuda a descubrir la causa del problema por ti mismo.

octubre 19, 2015 | Registered Commenterrickiees