elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Java
| | | |-+  Mi aplicacion en netbeans no funciona
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Mi aplicacion en netbeans no funciona  (Leído 3,523 veces)
zerojager

Desconectado Desconectado

Mensajes: 1


Ver Perfil
Mi aplicacion en netbeans no funciona
« en: 24 Febrero 2012, 19:14 pm »

soy principiante estoy trabajando con netbeans y estoy haciendo un programas que me muestre en un jtable las datos de un base de datos.

el programa funciona tomando el valor del jlist jcombobx y de radiobotton luego dependiendo la selecion me muestra la informacion que pido pero cuando hago una nueva seleccion el programa me tira el mismo dato al jtable aqui les muestro mi codigo.

import java.sql.*;
import java.util.Vector;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;


public class Examen extends javax.swing.JFrame {

Connection con;
Statement stm;
ResultSet rs;
Vector ls =new Vector();
Vector cb =new Vector();
Vector tb =new Vector();
Vector rd =new Vector();
DefaultListModel mlista = new DefaultListModel();
DefaultComboBoxModel mcombo = new DefaultComboBoxModel();
DefaultTableModel mtabla = new DefaultTableModel();

    public Examen() {
        initComponents();
        mtabla.addColumn("Resevacion");
        mtabla.addColumn("Fecha");
        mtabla.addColumn("Lote");
        mtabla.addColumn("Area");
        mtabla.addColumn("Valor");
       
       
        cmdlista.setModel(mlista);
        cmdcombo.setModel(mcombo);
        cmdtabla.setModel(mtabla);
       
     try{
     Class.forName("com.mysql.jdbc.Driver");
     con=DriverManager.getConnection("jdbc:mysql://localhost:3306/Reservacion","root","root");
     stm=con.createStatement();
     cargarlista();
     cargarcombo();
     }catch(Exception e){JOptionPane.showMessageDialog(this,e.getMessage());}
       
    }

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

        jButton1 = new javax.swing.JButton();
        peso = new javax.swing.JRadioButton();
        gringo = new javax.swing.JRadioButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        cmdlista = new javax.swing.JList();
        cmdcombo = new javax.swing.JComboBox();
        jScrollPane2 = new javax.swing.JScrollPane();
        cmdtabla = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton1.setText("Procesar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        peso.setText("Lempiras ");

        gringo.setText("Dolares");

        cmdlista.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings; }
        });
        jScrollPane1.setViewportView(cmdlista);

        cmdcombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        cmdtabla.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"
            }
        ));
        jScrollPane2.setViewportView(cmdtabla);

        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(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 424, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 101, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(gringo)
                            .addComponent(peso)
                            .addComponent(cmdcombo, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton1))
                        .addGap(59, 59, 59))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(60, 60, 60)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(cmdcombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(peso)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(gringo)
                        .addGap(18, 18, 18)
                        .addComponent(jButton1)))
                .addGap(60, 60, 60))
        );

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

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
       int p=0;   
    if (peso.isSelected())
       p=1;
    if (gringo.isSelected())
       p=2;
   
       try{
//el query para mostrar lainformacion que necesito           
rs=stm.executeQuery("select ReservacionID, Fecha, p.Nombre as Proyecto, v.Nombre as Vendedor, Lote, Area, Valor, m.Nombre as moneda from Reservacion as r inner join proyecto as p on r.ProyectoID = p.ProyectoID inner join Moneda as m on r.MonedaID = m.MonedaID inner join Vendedor as v on r.VendedorID = v.VendedorID where r.ProyectoID="+ls.get(this.cmdlista.getSelectedIndex())+" and r.VendedorID="+cb.get(this.cmdcombo.getSelectedIndex())+" and r.MonedaID="+p);
           
           while(rs.next()){
           tb.addElement(rs.getInt("ReservacionID"));
           tb.addElement(rs.getDate("Fecha"));
           tb.addElement(rs.getInt("Lote"));
           tb.addElement(rs.getFloat("Area"));
           tb.addElement(rs.getFloat("Valor"));
           mtabla.addRow(tb);
           }
       }catch(Exception e){JOptionPane.showMessageDialog(this,e.getMessage());}
   
    }                                       

    /**
     * @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(Examen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Examen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Examen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Examen.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 Examen().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JComboBox cmdcombo;
    private javax.swing.JList cmdlista;
    private javax.swing.JTable cmdtabla;
    private javax.swing.JRadioButton gringo;
    private javax.swing.JButton jButton1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JRadioButton peso;
    // End of variables declaration                   

public void cargarlista(){
       try{
          rs=stm.executeQuery("select * from Proyecto");
         
          while(rs.next()){
          mlista.addElement(rs.getString("Nombre"));
          ls.addElement(rs.getInt("ProyectoID"));
          }
       }catch(Exception e){JOptionPane.showMessageDialog(this,e.getMessage());}


public void cargarcombo(){
       try{
           rs=stm.executeQuery("select * from vendedor");
           
           while(rs.next()){
           mcombo.addElement(rs.getString("Nombre"));
           cb.addElement(rs.getInt("VendedorID"));
           }       
       }catch(Exception e){JOptionPane.showMessageDialog(this, e.getMessage());}
}

}
 


En línea

sapito169


Desconectado Desconectado

Mensajes: 628



Ver Perfil
Re: Mi aplicacion en netbeans no funciona
« Respuesta #1 en: 4 Marzo 2012, 01:33 am »

-el problema es que necesito de la base de datos para poder ejecutar tu sistema
-segundo no puedes mostrar tu aplicación completa y decir "resuelvanmelo" solo diciendo no sirve en primer lugar debes mostrar porque no sirve


En línea

visualfree

Desconectado Desconectado

Mensajes: 201


Ver Perfil
Re: Mi aplicacion en netbeans no funciona
« Respuesta #2 en: 17 Marzo 2012, 08:08 am »

coloca tus tablas y explica bien lo que quieres hacer y si tengo tiempo te hago un ejemplo...


Te recomiendo hacer todo a mano y luego cuando tengas mas experiencia escoje algun
IDE.

Saludos...
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Como hago una aplicacion limpia en netbeans?
Java
Xedrox 5 5,539 Último mensaje 14 Noviembre 2010, 02:37 am
por Xedrox
Ayuda insert netbeans utilizando palette de netbeans
Bases de Datos
luxferre 0 3,941 Último mensaje 6 Febrero 2012, 07:15 am
por luxferre
Compilando aplicacion C++ con Netbeans
Programación C/C++
turbofan 1 2,250 Último mensaje 9 Enero 2013, 19:04 pm
por alvr
Aplicación con sockets no funciona en LAN (sólo con localhost) « 1 2 »
Java
NathanD 10 6,429 Último mensaje 19 Noviembre 2013, 13:13 pm
por egyware
Cómo funciona Kaboom, la aplicación para la autodestrucción de mensajes de ...
Noticias
wolfbcn 0 1,939 Último mensaje 8 Mayo 2016, 13:42 pm
por wolfbcn
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines