[Netbeans] Carrello

di il
2 risposte

[Netbeans] Carrello

Salve a tutti,
sto implementando una simulazione di un sito di vendita online in java e ora devo inserire il carrello, su internet se ne trovano parecchi già implementati e ne ho trovato uno che, credevo, facesse al caso mio, ma con Netbeans sto avendo problemi

Ho copiato il codice in un file di testo.java, l'ho messo nella cartella del codice, ho eliminato tutto quello che poi dovrò riadattare ai miei scopi, in pratica è rimasta poca roba + il metodo initComponents(), ma netbeans non lo vede come tale e non mi mostra tutta la grafica dandomi errore.
Capisco che nella normalità, tale medoto è generato automaticamente, ma non credevo che mi desse tutti questi problemi!!

Come posso risolvere?!??

Grazie mille

2 Risposte

  • Re: [Netbeans] Carrello

    lady5 ha scritto:


    su internet se ne trovano parecchi già implementati e ne ho trovato uno
    Purtroppo hai detto ben poco. Che cosa è che hai trovato su internet? Spiega di più ... mostra il tuo codice e/o indica l'url di cosa hai trovato.
  • Re: [Netbeans] Carrello

    Sì hai ragione, scusatemi
    Questo è l'url del carrello
    e questo del gestoreCarrello

    Io ho ridotto il carrello così:
    
    import javax.swing.JOptionPane;
    import javax.swing.table.DefaultTableModel;
     
    public class Carrello extends javax.swing.JFrame {
        DefaultTableModel tableData;
        GestoreCarrello gestore;
        public Carrello() {
            tableData=gestore.getDefaultModel();
            initComponents();
            
       }
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
     
            jScrollPane2 = new javax.swing.JScrollPane();
            tab2 = new javax.swing.JTable();
            l1 = new javax.swing.JLabel();
            l2 = new javax.swing.JLabel();
            l3 = new javax.swing.JLabel();
            l4 = new javax.swing.JLabel();
            l5 = new javax.swing.JLabel();
            l6 = new javax.swing.JLabel();
            prosegui = new javax.swing.JButton();
            ricarica = new javax.swing.JButton();
            deleteAll = new javax.swing.JButton();
            goToLista = new javax.swing.JButton();
            help = new javax.swing.JButton();
            delete = new javax.swing.JButton();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
     
            tab2.getTableHeader().setReorderingAllowed(false);
            tab2.setModel(tableData);
            tab2.setShowHorizontalLines(false);
            jScrollPane2.setViewportView(tab2);
     
            l1.setText("Credito");
     
            l2.setText("Prezzo");
     
            l3.setText("Credito Residuo");
     
            l4.setText("jLabel4");
     
            l5.setText("jLabel5");
     
            l6.setText("jLabel6");
     
            prosegui.setText("Prosegui");
            prosegui.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                   
                }
            });
     
            ricarica.setText("Ricarica");
            ricarica.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    
                }
            });
     
            deleteAll.setText("Elimina tutto");
            deleteAll.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    
                }
            });
     
            goToLista.setText("Lista");
            goToLista.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                                }
            });
     
            help.setText("Credits");
            help.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    helpActionPerformed(evt);
                }
            });
     
            delete.setText("Elimina voce");
            delete.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                   
                }
            });
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane2)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap(12, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(help, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(goToLista, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(121, 121, 121)
                            .addComponent(ricarica, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(prosegui, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(l1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(l3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(l2, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 51, Short.MAX_VALUE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(l4)
                                .addComponent(l6)
                                .addComponent(l5))
                            .addGap(85, 85, 85)
                            .addComponent(delete, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(deleteAll, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(deleteAll, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(delete))
                            .addGap(124, 124, 124))
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(l1)
                                .addComponent(l4))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(l2)
                                .addComponent(l5))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(l3)
                                .addComponent(l6))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(prosegui)
                        .addComponent(ricarica)
                        .addComponent(goToLista)
                        .addComponent(help))
                    .addContainerGap())
            );
     
            java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
            setBounds((screenSize.width-569)/2, (screenSize.height-388)/2, 569, 388);
        }// </editor-fold>                        
     
        private void helpActionPerformed(java.awt.event.ActionEvent evt) {                                     
            JOptionPane.showMessageDialog(rootPane, "Sviluppatori:\n Giovanni Modica\n Giovanni Pisana\nPer recuperare la password mandare una mail a admin@admin.it\nTel: 0932 666666 \nFax:0932 666667 \nSito:www.videoteca.it ", "Credits", JOptionPane.INFORMATION_MESSAGE);
        }                                    
     
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Carrello();
                }
            });
        }
        // Variables declaration - do not modify                     
        private javax.swing.JButton delete;
        private javax.swing.JButton deleteAll;
        private javax.swing.JButton goToLista;
        private javax.swing.JButton help;
        private javax.swing.JScrollPane jScrollPane2;
        private javax.swing.JLabel l1;
        private javax.swing.JLabel l2;
        private javax.swing.JLabel l3;
        private javax.swing.JLabel l4;
        private javax.swing.JLabel l5;
        private javax.swing.JLabel l6;
        private javax.swing.JButton prosegui;
        private javax.swing.JButton ricarica;
        private javax.swing.JTable tab2;
        // End of variables declaration                   
    }
    
    

    e il gestoreCarrello così:
    
    import javax.swing.JOptionPane;
    import javax.swing.table.DefaultTableModel;
     
    class GestoreCarrello{
        DefaultTableModel tableData=new DefaultTableModel();
        String nome;
        public static String [] nomifilm=new String[4];
        public static int [] prezzifilm={0,0,0,0};
        int j=0;
        private static GestoreCarrello gestore1=new GestoreCarrello("Carrello");
        private GestoreCarrello(String nome){
            tableData.addColumn("Film");
            tableData.addColumn("Tipo");
            tableData.addColumn("Transazione");
            tableData.addColumn("Prezzo");
            this.nome=nome;
        }
        public static GestoreCarrello Istance(){
            return gestore1;
        }
        public DefaultTableModel getDefaultModel(){
            return tableData;
        }
        /*public void inserisciElementi(Product film,int prezzo){
            nomifilm[j]=film.getNome();
            prezzifilm[j]=prezzo;
            j++;
        }*/
        public void eliminaElemento(int index){
            nomifilm[index]="vuoto";
            prezzifilm[index]=0;
            j--;
        }
        public int aggiornaSpesa(){
            int credTot=0;
            for (int i=0;i<prezzifilm.length;i++){
                credTot+=prezzifilm[i];
            }
            return credTot;
        }
        public int aggiornaCredito(int credUtente){
            int credAgg=credUtente-aggiornaSpesa();
            if(credAgg<0) JOptionPane.showMessageDialog(null, "Credito Insufficiente - Cliccare sul bottone ricarica per aggiungere nuovo credito", "ATTENZIONE!", JOptionPane.INFORMATION_MESSAGE);
            return credAgg;
        }
        /*public void riempiStorico(String tipoTrans,int prezzo2,Product film){
            String prezzo=""+prezzo2;
            tableData.addRow(new String[]{film.getNome(),film.getTipo(),tipoTrans,prezzo});
        }*/
        public void eliminaVoceStorico(int index){
            tableData.removeRow(index);
        }
    }
    grazie mille
Devi accedere o registrarti per scrivere nel forum
2 risposte