Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
/*
*/
/*
* ingresoproductos.java
*/
package clases;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFormattedTextField;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
/**
* @author Usuario
*/
public ingresoproductos() {
initComponents();
mostrardatos("");
modelo.addColumn("CODIGO");
modelo.addColumn("DESCRIPCION");
modelo.addColumn("PRECIO UNITARIO");
tbproductos.setModel(modelo);
String sql="";
if(valor.equals(""))
else{
try {
Statement st = cn.createStatement();
ResultSet rs = st.executeQuery(sql);
while(rs.next()){
datos[0]=rs.getString(1);
datos[1]=rs.getString(2);
datos[2]=rs.getString(3);
modelo.addRow(datos);
tbproductos.setModel(modelo);
*/
@SuppressWarnings("unchecked")
jMenuItem1.setText("modificar");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
});
jPopupMenu1.add(jMenuItem1);
jMenuItem2.setText("eliminar");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
jMenuItem2ActionPerformed(evt);
});
jPopupMenu1.add(jMenuItem2);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Ingreso Productos");
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
setResizable(false);
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Detalle Producto"));
jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jLabel1.setText("Codigo");
txtcod.addActionListener(new java.awt.event.ActionListener() {
txtcodActionPerformed(evt);
}
});
txtcod.addKeyListener(new java.awt.event.KeyAdapter() {
txtcodKeyTyped(evt);
});
jLabel2.setText("Descripcion");
jLabel3.setText("Precio");
txtpre.addActionListener(new java.awt.event.ActionListener() {
txtpreActionPerformed(evt);
});
txtpre.addKeyListener(new java.awt.event.KeyAdapter() {
txtpreKeyTyped(evt);
});
btngrabar.setText("Grabar");
btngrabar.addActionListener(new java.awt.event.ActionListener() {
});
jButton3.setText("actualizar");
jButton3.addActionListener(new java.awt.event.ActionListener() {
jButton3ActionPerformed(evt);
});
jButton7.setText("Limpiar");
jButton7.addActionListener(new java.awt.event.ActionListener() {
jButton7ActionPerformed(evt);
});
jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/clases/mysql-
logo.png"))); // NOI18N
jLabel8.setIcon(new
javax.swing.ImageIcon("C:\\Users\\Julioguitars\\Desktop\\Java_Insert_Update_Delete_Display
\\Project
Code\\Java_Insert_Update_Delete_Display_Tutorial\\src\\java_insert_update_delete_display
_tutorial\\icons\\delete.png")); // NOI18N
jLabel10.setIcon(new
javax.swing.ImageIcon("C:\\Users\\Julioguitars\\Desktop\\Java_Insert_Update_Delete_Display
\\Project
Code\\Java_Insert_Update_Delete_Display_Tutorial\\src\\java_insert_update_delete_display
_tutorial\\icons\\add.png")); // NOI18N
tbproductos.setModel(new javax.swing.table.DefaultTableModel(
},
new String [] {
));
tbproductos.setComponentPopupMenu(jPopupMenu1);
jScrollPane1.setViewportView(tbproductos);
getContentPane().add(jScrollPane1, new
org.netbeans.lib.awtextra.AbsoluteConstraints(12, 192, 412, 320));
txtbuscar.addActionListener(new java.awt.event.ActionListener() {
txtbuscarActionPerformed(evt);
}
});
jButton1.addActionListener(new java.awt.event.ActionListener() {
jButton1ActionPerformed(evt);
});
jLabel4.setText("Lenin Gutierrez");
jLabel5.setText("Julio Perez");
jButton5.setText("Modificar");
jButton5.addActionListener(new java.awt.event.ActionListener() {
jButton5ActionPerformed(evt);
});
jButton6.setText("Salir");
jButton6.addActionListener(new java.awt.event.ActionListener() {
});
jLabel6.setIcon(new
javax.swing.ImageIcon(getClass().getResource("/clases/banderin.png"))); // NOI18N
jButton4.setText("Eliminar");
jButton4.addActionListener(new java.awt.event.ActionListener() {
jButton4ActionPerformed(evt);
});
jTextField1.addActionListener(new java.awt.event.ActionListener() {
jTextField1ActionPerformed(evt);
});
getContentPane().add(jTextField1, new
org.netbeans.lib.awtextra.AbsoluteConstraints(110, 160, 240, -1));
jMenu1.setText("File");
jMenu1.addActionListener(new java.awt.event.ActionListener() {
jMenu1ActionPerformed(evt);
}
});
jMenuItem3.setIcon(new
javax.swing.ImageIcon("C:\\Users\\Julioguitars\\Desktop\\iconfinder_Cancel_131742.png"));
// NOI18N
jMenuItem3.setText("Salir");
jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
jMenuItem3ActionPerformed(evt);
});
jMenu1.add(jMenuItem3);
jMenuBar1.add(jMenu1);
jMenu2.setText("Informacion");
jMenuItem5.setIcon(new
javax.swing.ImageIcon("C:\\Users\\Julioguitars\\Desktop\\informacion.png")); // NOI18N
jMenuItem5.setText("Acerca de");
jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
jMenuItem5ActionPerformed(evt);
});
jMenu2.add(jMenuItem5);
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
pack();
setLocationRelativeTo(null);
}// </editor-fold>
try {
pst.setString(1, txtcod.getText());
pst.setString(2, txtdes.getText());
pst.setString(3, txtpre.getText());
pst.executeUpdate();
mostrardatos("");
} catch (Exception e) {
System.out.print(e.getMessage());
mostrardatos(txtbuscar.getText());
if(fila>=0){
txtcod.setText(tbproductos.getValueAt(fila, 0).toString());
txtdes.setText(tbproductos.getValueAt(fila, 1).toString());
txtpre.setText(tbproductos.getValueAt(fila, 2).toString());
else{
try {
pst.executeUpdate();
mostrardatos("");
} catch (Exception e) {
System.out.print(e.getMessage());
String cod="";
cod=tbproductos.getValueAt(fila, 0).toString();
try {
pst.executeUpdate();
mostrardatos("");
} catch (Exception e) {
if(fila>=0){
txtcod.setText(tbproductos.getValueAt(fila, 0).toString());
txtdes.setText(tbproductos.getValueAt(fila, 1).toString());
txtpre.setText(tbproductos.getValueAt(fila, 2).toString());
else{
dispose();
String cod="";
cod=tbproductos.getValueAt(fila, 0).toString();
try {
PreparedStatement pst = cn.prepareStatement("DELETE FROM productos WHERE
codpro='"+cod+"'");
pst.executeUpdate();
mostrardatos("");
} catch (Exception e) {
txtcod.setText("");
txtpre.setText("");
txtdes.setText("");
char txtcod=evt.getKeyChar();
if (Character.isLetter(txtcod)) {
getToolkit().beep();
evt.consume();
}
private void txtpreKeyTyped(java.awt.event.KeyEvent evt) {
char txtpre=evt.getKeyChar();
if (Character.isLetter(txtpre)) {
getToolkit().beep();
evt.consume();
/**
*/
public static void main(String args[]) {
//<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.
*/
try {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
java.util.logging.Logger.getLogger(ingresoproductos.class.getName()).log(java.util.logging.Leve
l.SEVERE, null, ex);
java.util.logging.Logger.getLogger(ingresoproductos.class.getName()).log(java.util.logging.Leve
l.SEVERE, null, ex);
java.util.logging.Logger.getLogger(ingresoproductos.class.getName()).log(java.util.logging.Leve
l.SEVERE, null, ex);
java.util.logging.Logger.getLogger(ingresoproductos.class.getName()).log(java.util.logging.Leve
l.SEVERE, null, ex);
//</editor-fold>
new ingresoproductos().setVisible(true);
});