cantidad de productos de cada tipo.
total de dinero en artículos.
porcentaje de artículos de tipo 2.
Y articulo con el precio mas elevado.
Ya realice la carga de artículos y la otra pantalla que muestra todos los artículos cargados.
Mi problema es la ventana de consulta que muestra específicamente ciertos datos.
Este es mi código, si alguien me puede dar una mano por favor. Tengo un examen pronto y la verdad que eso me esta complicando la vida.
https://www.mediafire.com/?6tzn3g25uhv07fu
Main Class
Código
]public class Clase14Quiosco { MenuPrincipal v = new MenuPrincipal(); v.setVisible(true); } }
MenuPrincipal class
Código
import java.util.ArrayList; import javax.swing.JOptionPane; private ArrayList<Articulo> listaArticulos; public MenuPrincipal() { initComponents(); listaArticulos = new ArrayList<>(); } private void initComponents() { jMenu1.setText("Articulos"); jMenu1ActionPerformed(evt); } }); jMenuItem1.setText("Alta"); jMenuItem1ActionPerformed(evt); } }); jMenu1.add(jMenuItem1); jMenuBar1.add(jMenu1); jMenu2.setText("Reportes"); jMenuItem2.setText("Listado"); jMenuItem2ActionPerformed(evt); } }); jMenu2.add(jMenuItem2); jMenuBar1.add(jMenu2); setJMenuBar(jMenuBar1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) ); pack(); }// </editor-fold> } AltaArticulo v = new AltaArticulo(listaArticulos); v.setVisible(true); } ConsultaArticulos v = new ConsultaArticulos(listaArticulos); v.setVisible(true); } // Variables declaration - do not modify // End of variables declaration }
AltaArticulo class
Código
import java.util.ArrayList; import javax.swing.JOptionPane; private ArrayList<Articulo> listaArticulos; public AltaArticulo() { initComponents(); } public AltaArticulo(ArrayList<Articulo> listaArticulos) { initComponents(); this.listaArticulos = listaArticulos; } private void initComponents() { jLabel1.setText("Codigo"); jLabel2.setText("Nombre"); jLabel3.setText("Precio"); jLabel4.setText("Stock actual"); jLabel5.setText("Stock mínimo"); jLabel6.setText("Categoria"); txtCodigoActionPerformed(evt); } }); cboCategoria.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Almacen", "Perfumeria", "Otros" })); btnAgregar.setText("Agregar"); btnAgregarActionPerformed(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() .addGap(46, 46, 46) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel2) .addComponent(jLabel1) .addComponent(jLabel6) .addComponent(jLabel5) .addComponent(jLabel3) .addComponent(jLabel4)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(btnAgregar) .addComponent(txtCodigo) .addComponent(txtNombre) .addComponent(txtPrecio) .addComponent(txtStockActual) .addComponent(txtStockMinimo)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(26, 26, 26) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtStockActual, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtStockMinimo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cboCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addComponent(btnAgregar) ); pack(); }// </editor-fold> int categoria = cboCategoria.getSelectedIndex()+1; Articulo nuevo = new Articulo(); nuevo.setCodigo(codigo); nuevo.setNombre(nombre); nuevo.setPrecio(precio); nuevo.setStockActual(stockActual); nuevo.setStockMinimo(stockMinimo); nuevo.setCategoria(categoria); listaArticulos.add(nuevo); } // TODO add your handling code here: } try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { break; } } java.util.logging.Logger.getLogger(AltaArticulo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(AltaArticulo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(AltaArticulo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(AltaArticulo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> public void run() { new AltaArticulo().setVisible(true); } }); } // Variables declaration - do not modify // End of variables declaration }
ConsultaArticulos class
Código
import java.util.ArrayList; public ConsultaArticulos() { initComponents(); } public ConsultaArticulos(ArrayList<Articulo> listaArticulos) { initComponents(); lstArticulos.setListData(listaArticulos.toArray()); } private void initComponents() { jScrollPane1.setViewportView(lstArticulos); pack(); }// </editor-fold> try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { break; } } java.util.logging.Logger.getLogger(ConsultaArticulos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(ConsultaArticulos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(ConsultaArticulos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(ConsultaArticulos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> public void run() { new ConsultaArticulos().setVisible(true); } }); } // Variables declaration - do not modify // End of variables declaration }
Articulo class
Código
public class Articulo { private int codigo; private float precio; private int stockActual; private int stockMinimo; private int categoria; public Articulo() { } public int getCodigo() { return codigo; } public void setCodigo(int codigo) { this.codigo = codigo; } return nombre; } this.nombre = nombre; } public float getPrecio() { return precio; } public void setPrecio(float precio) { this.precio = precio; } public int getStockActual() { return stockActual; } public void setStockActual(int stockActual) { this.stockActual = stockActual; } public int getStockMinimo() { return stockMinimo; } public void setStockMinimo(int stockMinimo) { this.stockMinimo = stockMinimo; } public int getCategoria() { return categoria; } public void setCategoria(int categoria) { this.categoria = categoria; } @Override return "Articulo{" + "codigo=" + codigo + ", nombre=" + nombre + ", precio=" + precio + ", stockActual=" + stockActual + ", stockMinimo=" + stockMinimo + ", categoria=" + categoria + '}'; } }