Gracias Caballero, segui trabajando y hasta el momento tengo esto, quisiera saber que debo arreglarle?
CODIGO COMPRAS
package supercompras.modelo;
public class Compras { /** * @attribute */ private int Cantidad;
/** * @attribute */ private double Subtotal;
/** * @attribute */ private double DescuentoPor;
/** * @attribute */ private double DescuentoDin;
/** * @attribute */ final public static double Iva=16/100;
/** * @attribute */ private int Total;
public Compras() { Cantidad = 0; DescuentoDin = 0; Subtotal = 0; Total = 0; } public void asignarCompras(int Cantidad, int DescuentoDin, int Subtotal, int Total){ Cantidad = 0; DescuentoDin = 0; Subtotal = 0; Total = 0; }
public int getCantidad() { return Cantidad; }
public double getDescuentoPor() { return DescuentoPor; }
public double getDescuentoDin() { return DescuentoDin; }
public double getIva() { return Iva; }
public double getSubtotal() { return Subtotal; }
public int getTotal() { return Total; }
public void calcularDescuentoPor() { if (Cantidad>=6 && Cantidad<=10) DescuentoPor= (int)(0.02); if (Cantidad>=11 && Cantidad<=15) DescuentoPor= (int)(0.045); if (Cantidad>=16) DescuentoPor= (int)(0.06); else DescuentoPor= (int)(0.0); }
public void calcularDescuentoDin(double Iva) { if (Cantidad>=6 && Cantidad<=10) DescuentoDin= (int)(Subtotal*0.02); if (Cantidad>=11 && Cantidad<=15) DescuentoDin= (int)(Subtotal*0.045); if (Cantidad>=16) DescuentoDin= (int)(Subtotal*0.06); else DescuentoDin= (int)(0.0); }
public void calcularIva() { }
public void calcularSubtotal() { }
public void calcularTotal() { Total = (int)(Subtotal+DescuentoDin+Iva); } }
CODIGO PRODUCTO
package supercompras.modelo;
public class Producto { /** * @attribute */ private int CodigoProd;
/** * @attribute */ private String DescripcionProd;
/** * @attribute */ private int PrecioProd;
/** * @attribute */ private int StockProd;
public Producto() { CodigoProd = 0; PrecioProd = 0; StockProd = 0; }
public int getStockProd() { return StockProd; }
public int getCodigoProd() { return CodigoProd; }
public String getDescripcionProd() { return DescripcionProd; }
public int getPrecioProd() { return PrecioProd; } }
CODIGO PROVEEDOR
package supercompras.modelo;
public class Proveedor { /** * @attribute */ private int NitProv;
/** * @attribute */ private String DescripcionProv;
public Proveedor() { NitProv= 0; }
public String getDescripcionProv() { return DescripcionProv; }
public int getNitProv() { return NitProv; } }
FRAME1
package supercompras.modelo;
import java.awt.Color; import java.awt.Dimension;
import java.awt.EventQueue; import java.awt.Font; import java.awt.Rectangle;
import java.awt.event.ActionEvent; import java.awt.event.ActionListener;
import java.text.DecimalFormat; import java.text.NumberFormat;
import javax.swing.BorderFactory; import javax.swing.DefaultComboBoxModel; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JTextField; import javax.swing.SwingConstants; //import javax.swing.Swing.JOptioPane; //import javax.text.DecimalFormat; //import javax.text.NubmerFormat;
public class Frame1 extends JFrame { private Compras compras[] = new Compras[5]; private Producto producto = new Producto(); private Proveedor proveedor = new Proveedor(); private JLabel jLabel1 = new JLabel(); private JLabel jLabel2 = new JLabel(); private JTextField jTextField1 = new JTextField(); private JLabel jLabel3 = new JLabel(); private JLabel jLabel4 = new JLabel(); private JLabel jLabel5 = new JLabel(); private JLabel jLabel6 = new JLabel(); private JLabel jLabel7 = new JLabel(); private JTextField jTextField2 = new JTextField(); private JTextField jTextField3 = new JTextField(); private JTextField jTextField4 = new JTextField(); private JComboBox jComboBox1 = new JComboBox(); private JLabel jLabel8 = new JLabel(); private JLabel jLabel9 = new JLabel(); private JLabel jLabel10 = new JLabel(); private JLabel jLabel11 = new JLabel(); private JLabel jLabel12 = new JLabel(); private JTextField jTextField5 = new JTextField(); private JTextField jTextField6 = new JTextField(); private JTextField jTextField7 = new JTextField(); private JTextField jTextField8 = new JTextField(); private JTextField jTextField9 = new JTextField(); private JButton jButton1 = new JButton(); private JButton jButton2 = new JButton(); private JButton jButton3 = new JButton(); private JButton jButton4 = new JButton(); private JButton jButton5 = new JButton(); private JButton jButton6 = new JButton(); private JButton jButton7 = new JButton(); private JButton jButton8 = new JButton(); private JButton jButton9 = new JButton();
public Frame1() { try { jbInit(); } catch (Exception e) { e.printStackTrace(); } }
private void jbInit() throws Exception { this.getContentPane().setLayout( null ); this.setSize(new Dimension(550, 567)); this.setForeground(new Color(247, 255, 214)); this.setBackground(new Color(0, 132, 198)); jLabel1.setBounds(new Rectangle(200, 10, 245, 30)); jLabel1.setText("PROGRAMA DE COMPRAS"); jLabel1.setFont(new Font("Tahoma", 1, 17)); jLabel2.setText("Proveedor"); jLabel2.setBounds(new Rectangle(45, 60, 75, 20)); jLabel2.setFont(new Font("Tahoma", 1, 13)); jTextField1.setBounds(new Rectangle(130, 60, 150, 25)); jLabel3.setText("Producto"); jLabel3.setBounds(new Rectangle(10, 100, 80, 30)); jLabel3.setFont(new Font("Tahoma", 1, 13)); jLabel3.setBackground(Color.cyan); jLabel3.setBorder(BorderFactory.createLineBorder(Color.black, 1)); jLabel3.setHorizontalAlignment(SwingConstants.CENTER); jLabel3.setHorizontalTextPosition(SwingConstants.CENTER); jLabel4.setText("Producto"); jLabel4.setBounds(new Rectangle(65, 145, 70, 15)); jLabel4.setFont(new Font("Tahoma", 1, 13)); jLabel5.setText("Cantidad"); jLabel5.setBounds(new Rectangle(220, 145, 85, 15)); jLabel5.setFont(new Font("Tahoma", 1, 13)); jLabel6.setText("Precio U."); jLabel6.setBounds(new Rectangle(335, 145, 80, 15)); jLabel6.setFont(new Font("Tahoma", 1, 13)); jLabel7.setText("Subtotal"); jLabel7.setBounds(new Rectangle(440, 145, 70, 15)); jLabel7.setFont(new Font("Tahoma", 1, 13)); jTextField2.setBounds(new Rectangle(210, 175, 105, 25)); jTextField3.setBounds(new Rectangle(325, 175, 90, 25)); jTextField4.setBounds(new Rectangle(425, 175, 95, 25)); jComboBox1.setBounds(new Rectangle(55, 175, 135, 25)); jComboBox1.setLightWeightPopupEnabled(false); jLabel8.setText("Subtotal"); jLabel8.setBounds(new Rectangle(315, 225, 65, 20)); jLabel8.setFont(new Font("Tahoma", 1, 13)); jLabel8.setSize(new Dimension(100, 15)); jLabel9.setText("Descuento %"); jLabel9.setBounds(new Rectangle(315, 265, 110, 15)); jLabel9.setFont(new Font("Tahoma", 1, 13)); jLabel9.setSize(new Dimension(100, 15)); jLabel10.setText("Descuento $"); jLabel10.setBounds(new Rectangle(315, 300, 85, 15)); jLabel10.setFont(new Font("Tahoma", 1, 13)); jLabel10.setSize(new Dimension(100, 15)); jLabel11.setText("IVA"); jLabel11.setBounds(new Rectangle(315, 335, 80, 15)); jLabel11.setFont(new Font("Tahoma", 1, 13)); jLabel11.setSize(new Dimension(100, 15)); jLabel12.setText("TOTAL"); jLabel12.setBounds(new Rectangle(315, 370, 85, 15)); jLabel12.setFont(new Font("Tahoma", 1, 13)); jLabel12.setSize(new Dimension(100, 15)); jTextField5.setBounds(new Rectangle(430, 220, 90, 20)); jTextField6.setBounds(new Rectangle(430, 260, 90, 20)); jTextField7.setBounds(new Rectangle(430, 295, 90, 20)); jTextField8.setBounds(new Rectangle(430, 330, 90, 20)); jTextField9.setBounds(new Rectangle(430, 365, 90, 20)); jButton1.setText("Adicionar"); jButton1.setBounds(new Rectangle(10, 410, 90, 28)); jButton1.setSize(new Dimension(90, 28)); jButton1.setBackground(new Color(0, 132, 198)); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jButton1_actionPerformed(e); } }); jButton2.setText("Buscar"); jButton2.setBounds(new Rectangle(115, 410, 90, 28)); jButton2.setSize(new Dimension(90, 28)); jButton2.setBackground(new Color(0, 132, 198)); jButton3.setText("Borrar"); jButton3.setBounds(new Rectangle(210, 410, 90, 28)); jButton3.setSize(new Dimension(90, 28)); jButton3.setBackground(new Color(0, 132, 198)); jButton4.setText("Modificar"); jButton4.setBounds(new Rectangle(305, 410, 90, 28)); jButton4.setSize(new Dimension(90, 28)); jButton4.setBackground(new Color(0, 132, 198)); jButton5.setText("Primero"); jButton5.setBounds(new Rectangle(10, 455, 90, 28)); jButton5.setSize(new Dimension(90, 28)); jButton5.setBackground(new Color(0, 132, 198)); jButton6.setText("Anterior"); jButton6.setBounds(new Rectangle(115, 455, 90, 28)); jButton6.setSize(new Dimension(90, 28)); jButton6.setBackground(new Color(0, 132, 198)); jButton7.setText("Siguiente"); jButton7.setBounds(new Rectangle(210, 455, 90, 28)); jButton7.setSize(new Dimension(90, 28)); jButton7.setBackground(new Color(0, 132, 198)); jButton8.setText("Ultimo"); jButton8.setBounds(new Rectangle(305, 455, 90, 28)); jButton8.setSize(new Dimension(90, 28)); jButton8.setBackground(new Color(0, 132, 198)); jButton9.setText("Salir"); jButton9.setBounds(new Rectangle(425, 455, 90, 28)); jButton9.setSize(new Dimension(90, 28)); jButton9.setBackground(new Color(0, 132, 198)); jButton9.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jButton9_actionPerformed(e); } }); this.getContentPane().add(jButton9, null); this.getContentPane().add(jButton8, null); this.getContentPane().add(jButton7, null); this.getContentPane().add(jButton6, null); this.getContentPane().add(jButton5, null); this.getContentPane().add(jButton4, null); this.getContentPane().add(jButton3, null); this.getContentPane().add(jButton2, null); this.getContentPane().add(jButton1, null); this.getContentPane().add(jTextField9, null); this.getContentPane().add(jTextField8, null); this.getContentPane().add(jTextField7, null); this.getContentPane().add(jTextField6, null); this.getContentPane().add(jTextField5, null); this.getContentPane().add(jLabel12, null); this.getContentPane().add(jLabel11, null); this.getContentPane().add(jLabel10, null); this.getContentPane().add(jLabel9, null); this.getContentPane().add(jLabel8, null); this.getContentPane().add(jComboBox1, null); this.getContentPane().add(jTextField4, null); this.getContentPane().add(jTextField3, null); this.getContentPane().add(jTextField2, null); this.getContentPane().add(jLabel7, null); this.getContentPane().add(jLabel6, null); this.getContentPane().add(jLabel5, null); this.getContentPane().add(jLabel4, null); this.getContentPane().add(jLabel3, null); this.getContentPane().add(jTextField1, null); this.getContentPane().add(jLabel2, null); this.getContentPane().add(jLabel1, null); jComboBox1.setModel(new DefaultComboBoxModel());
} private void btnSalir_actionPerformed(ActionEvent e) { dispose(); } public static void main(String args[]) { EventQueue.invokeLater(new Runnable() { public void run() { new Frame1().setVisible(true); } });
} private void jComboBox1_actionPerformed(ActionEvent e) { }
private void jButton9_actionPerformed(ActionEvent e) { dispose(); }
private void jButton1_actionPerformed(ActionEvent e) { int i = 0, cantidad=0, valor=0; String cadena, proveedor, apellido; proveedor = JOptionPane.showInputDialog("NOMBRE PROVEEDOR"); cadena = JOptionPane.showInputDialog("CANTIDAD DE PRODUCTO"); cantidad = Integer.parseInt(cadena); cadena = JOptionPane.showInputDialog("INGRESE VALOR UNITARIO"); valor = Integer.parseInt(cadena); compras = new Compras(); compras.asignarCompras(proveedor, cantidad, valor); compras.calcularDescuentoPor(Integer.parseInt(cadena)); compras.calcularDescuentoDin(Integer.parseInt(cadena)); compras.calcularSubtotal(); compras.calcularTotal(Integer.parseInt(cadena)); mostrar(i); i++; } public void mostrar(int i) { DecimalFormat df = ( DecimalFormat )NumberFormat.getInstance( ); df.applyPattern( "$###,##0.##" ); jTextField1.setText(String.valueOf((compras.getDescripcionProv()))); jTextField2.setText(df.format(compras.getCantidad())); jTextField3.setText(df.format(compras.getPrecioProd())); jTextField4.setText(df.format(compras.getSubtotal())); jTextField5.setText(df.format(compras.getSubtotal())); jTextField6.setText(df.format(compras.getDescuentoPor())); jTextField7.setText(df.format(compras.getDescuentoDin())); jTextField8.setText(df.format(compras.getTotal())); } }
Le Agradezco su opinión.
|