jueves, 24 de julio de 2014

Orden de Compra de Reciclaje en Java

Basicamente se hace uso de Jtable o tablas de un comboBox y un cuadro de texto, se simula compra de reciclaje.
El comboBox tiene por nombre cmbTipo, el grid tblPro, el cuadro de texto txtPeso, las etiquetas txtSub, txtTax y txtTotal, el boton nuevo btnNuevo.
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
public class frmBotellas extends javax.swing.JFrame {
DefaultTableModel modelo=new DefaultTableModel();
    public frmBotellas() {
        initComponents();
        String titu[]={"Tipo","Peso","$/lb","Importe"};
        modelo.setColumnIdentifiers(titu);
        tblPro.setModel(modelo);
    }
private void btnAgregarActionPerformed(java.awt.event.ActionEvent evt) {                                           
        int itipo=cmbTipo.getSelectedIndex();
        String datos[]={"1","2","3","4"};
        switch (itipo){
            case 0:datos[0]="Aluminio";datos[2]="2.01";break;
            case 1:datos[0]="Plastico CRV";datos[2]="1.01";break;
            case 2:datos[0]="Metal";datos[2]="1.5";break;
        }
        datos[1]=txtPeso.getText();
        datos[3]=Float.parseFloat(datos[2])*Float.parseFloat(datos[1])+"";
        modelo.addRow(datos);
        calTota();
    }                                          

    private void btnNuevoActionPerformed(java.awt.event.ActionEvent evt) {                                         
        cmbTipo.setSelectedIndex(-1);
        txtPeso.setText(null);
        cleanTable();
        txtSub.setText(null);
        txtTax.setText(null);
        txtTotal.setText(null);
    }                                        

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        if (tblPro.getSelectedRow()>-1){
            int i=tblPro.getSelectedRow();
            modelo.removeRow(i);
            calTota();
        }else{JOptionPane.showMessageDialog(null, "Seleccione Fila");}
    }                                        
    private void cleanTable(){
        while (modelo.getRowCount()>0){
        modelo.removeRow(modelo.getRowCount()-1);
        }
    }
    private void calTota(){
        float Sub=0;
        float tax,total;
        if (tblPro.getRowCount()>0){
            for(int i=0;i<tblPro.getRowCount();i++){
                Sub=Sub+Float.parseFloat(modelo.getValueAt(i, 3).toString());
            }
        }
        txtSub.setText(redo(Sub)+"");
        tax=(float) (Sub*0.09);
        txtTax.setText(redo(tax)+"");
        total=Sub+tax;
        txtTotal.setText(redo(total)+"");
    }
    private float redo(float N){
        return (float) (Math.rint(N*100)/100);
    }




miércoles, 16 de julio de 2014

Solucion a un Sistema de Ecuaciones Lineales de 3x3 con Java

Se realiza el siguiente diseño
package editar;
import javax.swing.table.DefaultTableModel;
public class frmEcuaciones extends javax.swing.JFrame {
Double a11,a12,a13,a21,a22,a23,a31,a32,a33;
DefaultTableModel modelo=new DefaultTableModel();
    public frmEcuaciones() {
        initComponents();
        String titu[]={"X","Y","Z","B"};
        modelo.setColumnIdentifiers(titu);
        tblA.setModel(modelo);
        String datos[]={"2","4","-3","12"};
        String datos2[]={"3","-5","2","13"};
        String datos3[]={"-1","3","2","17"};
        modelo.addRow(datos);
        modelo.addRow(datos2);
        modelo.addRow(datos3);
    }
    private Double redo(Double N){
        return (Math.rint(N*100)/100);
    }
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
       Double a,ax,ay,az,b1,b2,b3;
        b1=Double.parseDouble(modelo.getValueAt(0, 3).toString());
        b2=Double.parseDouble(modelo.getValueAt(1, 3).toString());
        b3=Double.parseDouble(modelo.getValueAt(2, 3).toString());
        captura();
        a=deter();
        a11=b1;a21=b2;a31=b3;
        ax=deter();
        captura();
        a12=b1;a22=b2; a32=b3;
        ay=deter();
        captura();
        a13=b1;a23=b2;a33=b3;
        az=deter();
        lblX.setText("X="+redo(ax/a)+"");
        lblY.setText("Y="+redo(ay/a)+"");
        lblZ.setText("Z="+redo(az/a)+"");
    }                                        
    private void captura(){
        a11=Double.parseDouble(modelo.getValueAt(0, 0).toString());
        a12=Double.parseDouble(modelo.getValueAt(0, 1).toString());
        a13=Double.parseDouble(modelo.getValueAt(0, 2).toString());
        a21=Double.parseDouble(modelo.getValueAt(1, 0).toString());
        a22=Double.parseDouble(modelo.getValueAt(1, 1).toString());
        a23=Double.parseDouble(modelo.getValueAt(1, 2).toString());
        a31=Double.parseDouble(modelo.getValueAt(2, 0).toString());
        a32=Double.parseDouble(modelo.getValueAt(2, 1).toString());
        a33=Double.parseDouble(modelo.getValueAt(2, 2).toString());
    }
    private Double deter(){
        Double d;
        d=(a11*a22*a33+a12*a23*a31+a13*a21*a32)-(a13*a22*a31+a12*a21*a33+a11*a23*a32);
        return d;
    }
tambien obtiene la solucion con decimales
download code here


lunes, 14 de julio de 2014

Programar Radio Button en Java

Primero agregamos los radio button a un formulario.
Luego agregamos un button group el cual no se ve en el formulario

 Luego seleccionamos el primer radio button y en propiedades en buttongroup escogemos buttonGroup1, igual para el 2 y 3 radiobutton
 Luego agregamos un boton enviar
y codificamos lo siguiente en su evento actionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        if (jRadioButton1.isSelected()){
            JOptionPane.showMessageDialog(null, "Aluminio Seleccionado");
        }
        if (jRadioButton2.isSelected()){JOptionPane.showMessageDialog(null, "Plastico CRV Seleccionado");}
        if (jRadioButton3.isSelected()){JOptionPane.showMessageDialog(null, "Metal Seleccionado");}
    }  

Hallar las raizes de Cualquier Ecuacion con Excel 365

  Se establece un intervalo de x de -20 a 20 para hallar los f(x) que cambian de signo, X aumenta en 1.   Se halla el cambio de signo de f(x...