domingo, 13 de diciembre de 2009

CALCULADORA

public class Operaciones {
static double resultado;
public Operaciones(){
resultado = 0;
}

public static double seno(double x){
resultado = Math.sin(x);
return resultado;
}

public static double coseno(double x){
resultado = Math.cos(x);
return resultado;
}

public static double tangente(double x){
resultado = Math.tan(x);
return resultado;
}

public static double logaritmo(double x){
resultado = Math.log(x);
return resultado;
}

public static double raiz(double x){
if(x>=0){
resultado = Math.sqrt(x);
}else{
System.out.println("Solo valores postivos");
resultado = 0;
}
return resultado;

}

public static double suma(double x, double y){

resultado = x+y;

return resultado;
}

public static double resta(double x, double y){

resultado = x-y;

return resultado;
}
public static double multiplicacion(double x, double y){

resultado = x*y;

return resultado;
}

public static double division(double x, double y){

resultado = x/y;

return resultado;
}

public static void main(String args[]){
double y;
//Operaciones p = new Operaciones();
y = seno(3.141516);
System.out.println("El seno "+y);
}

}


public class MisOperaciones extends javax.swing.JApplet {

/** Initializes the applet MisOperaciones */
public void init() {
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
initComponents();
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}

/** This method is called from within the init() method to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
//
private void initComponents() {

jPanel1 = new javax.swing.JPanel();
jTextField1 = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jButton7 = new javax.swing.JButton();
jButton8 = new javax.swing.JButton();
jButton9 = new javax.swing.JButton();
jButton10 = new javax.swing.JButton();
jButton11 = new javax.swing.JButton();
jButton12 = new javax.swing.JButton();
jButton13 = new javax.swing.JButton();
jButton14 = new javax.swing.JButton();
jButton15 = new javax.swing.JButton();
jButton16 = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jButton17 = new javax.swing.JButton();
jButton18 = new javax.swing.JButton();
jButton19 = new javax.swing.JButton();
jButton20 = new javax.swing.JButton();
jTextField2 = new javax.swing.JTextField();

jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});

jLabel1.setText("Variable");

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

jButton2.setText("coseno");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

jButton3.setText("tangente");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});

jButton4.setText("Raiz");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});

jButton5.setText("1");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});

jButton6.setText("2");
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton6ActionPerformed(evt);
}
});

jButton7.setText("3");
jButton7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton7ActionPerformed(evt);
}
});

jButton8.setText("4");
jButton8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton8ActionPerformed(evt);
}
});

jButton9.setText("5");
jButton9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton9ActionPerformed(evt);
}
});

jButton10.setText("6");
jButton10.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton10ActionPerformed(evt);
}
});

jButton11.setText("7");
jButton11.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton11ActionPerformed(evt);
}
});

jButton12.setText("8");
jButton12.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton12ActionPerformed(evt);
}
});

jButton13.setText("9");
jButton13.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton13ActionPerformed(evt);
}
});

jButton14.setText("+");
jButton14.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton14ActionPerformed(evt);
}
});

jButton15.setText("0");
jButton15.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton15ActionPerformed(evt);
}
});

jButton16.setText(".");
jButton16.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton16ActionPerformed(evt);
}
});

jLabel2.setText("Resultados");

jButton17.setText("logaritmo");
jButton17.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton17ActionPerformed(evt);
}
});

jButton18.setText("-");
jButton18.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton18ActionPerformed(evt);
}
});

jButton19.setText("*");
jButton19.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton19ActionPerformed(evt);
}
});

jButton20.setText("/");
jButton20.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton20ActionPerformed(evt);
}
});

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jButton4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton8)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton9)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton10)
.addGap(18, 18, 18)
.addComponent(jButton18))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jButton14)
.addComponent(jButton11))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton12)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton13)
.addGap(18, 18, 18)
.addComponent(jButton19))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton15)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton16)
.addGap(18, 18, 18)
.addComponent(jButton20))))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton7)
.addGap(18, 18, 18)
.addComponent(jButton17))
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(127, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE)
.addGap(273, 273, 273))))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(26, 26, 26)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton5)
.addComponent(jButton6)
.addComponent(jButton7)
.addComponent(jButton17))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton2)
.addComponent(jButton8)
.addComponent(jButton9)
.addComponent(jButton10)
.addComponent(jButton18))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton3)
.addComponent(jButton11)
.addComponent(jButton12)
.addComponent(jButton13)
.addComponent(jButton19))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton4)
.addComponent(jButton14)
.addComponent(jButton15)
.addComponent(jButton16)
.addComponent(jButton20))
.addGap(18, 18, 18)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(51, Short.MAX_VALUE))
);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
}//


private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here
aux += 1;
jTextField1.setText(aux);
}

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
aux += 2;
jTextField1.setText(aux);
}

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
aux += 3;
jTextField1.setText(aux);
}

private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
aux += ".";
jTextField1.setText(aux);
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String aux1 = jTextField1.getText();
double r = Double.parseDouble(aux1);
r = Operaciones.seno(r);
jLabel2.setText("El seno de "+aux1+ " es :\n "+r);
aux = "";
jTextField1.setText(aux);
}

private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {
aux += 4;
jTextField1.setText(aux); // TODO add your handling code here:
}

private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {
aux += 5;
jTextField1.setText(aux); // TODO add your handling code here:
}

private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
aux += 6;
jTextField1.setText(aux);
}

private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
aux += 7;
jTextField1.setText(aux);
}

private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
aux += 8;
jTextField1.setText(aux);
}

private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
aux += 9;
jTextField1.setText(aux);
}

private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
aux += 0;
jTextField1.setText(aux);
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String aux1 = jTextField1.getText();
double r = Double.parseDouble(aux1);
r = Operaciones.coseno(r);
jLabel2.setText("El coseno de "+aux1+ " es :\n "+r);
aux = "";
jTextField1.setText(aux);
}

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String aux1 = jTextField1.getText();
double r = Double.parseDouble(aux1);
r = Operaciones.tangente(r);
jLabel2.setText("la tangente de "+aux1+ " es :\n "+r);
aux = "";
jTextField1.setText(aux);
}

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String aux1 = jTextField1.getText();
double r = Double.parseDouble(aux1);
r = Operaciones.raiz(r);
jLabel2.setText("La raiz de "+aux1+ " es :\n "+r);
aux = "";
jTextField1.setText(aux);
}

private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String aux1 = jTextField1.getText();
double y = Double.parseDouble(aux1);
String aux2 = jTextField2.getText();
double x = Double.parseDouble(aux2);

// double r = Double.parseDouble(aux1, aux2);
// r = y.Operaciones.suma(x);
jLabel2.setText("Suma = es :\n "+(Operaciones.suma(x, y)));
aux = "";
jTextField1.setText(aux);
aux = "";
jTextField2.setText(aux);


}

private void jButton17ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String aux1 = jTextField1.getText();
double r = Double.parseDouble(aux1);
r = Operaciones.logaritmo(r);
jLabel2.setText("El logaritmo de "+aux1+ " es :\n "+r);
aux = "";
jTextField1.setText(aux);
}

private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void jButton18ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:

String aux1 = jTextField1.getText();
double y = Double.parseDouble(aux1);
String aux2 = jTextField2.getText();
double x = Double.parseDouble(aux2);

// double r = Double.parseDouble(aux1, aux2);
// r = y.Operaciones.suma(x);
jLabel2.setText("Resta = es :\n "+(Operaciones.resta(x, y)));
aux = "";
jTextField1.setText(aux);
aux = "";
jTextField2.setText(aux);
}

private void jButton19ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String aux1 = jTextField1.getText();
double y = Double.parseDouble(aux1);
String aux2 = jTextField2.getText();
double x = Double.parseDouble(aux2);

// double r = Double.parseDouble(aux1, aux2);
// r = y.Operaciones.suma(x);
jLabel2.setText("Multiplicacion = es :\n "+(Operaciones.multiplicacion(x,y)));
aux = "";
jTextField1.setText(aux);
aux = "";
jTextField2.setText(aux);
}

private void jButton20ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String aux1 = jTextField1.getText();
double y = Double.parseDouble(aux1);
String aux2 = jTextField2.getText();
double x = Double.parseDouble(aux2);

// double r = Double.parseDouble(aux1, aux2);
// r = y.Operaciones.suma(x);
jLabel2.setText("division = es :\n "+(Operaciones.division(x, y)));
aux = "";
jTextField1.setText(aux);
aux = "";
jTextField2.setText(aux);
}
public String aux="";
public String aux3;

// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton10;
private javax.swing.JButton jButton11;
private javax.swing.JButton jButton12;
private javax.swing.JButton jButton13;
private javax.swing.JButton jButton14;
private javax.swing.JButton jButton15;
private javax.swing.JButton jButton16;
private javax.swing.JButton jButton17;
private javax.swing.JButton jButton18;
private javax.swing.JButton jButton19;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton20;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton7;
private javax.swing.JButton jButton8;
private javax.swing.JButton jButton9;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
// End of variables declaration

}





domingo, 6 de diciembre de 2009

Resta,Multiplicacion,Transpuesta...Con botones

//MATRIZ
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class Matriz {
public int numeroFilas;
public int numeroColumnas;
public double [][]matriz;

public Matriz(){
}

public Matriz(int nF, int nC){

numeroFilas=nF;
numeroColumnas=nC;
matriz=new double[numeroFilas][numeroColumnas];//construyo un sitio para almacenar ceros
for(int i=0;i < numeroFilas;i++)
for(int j=0; j < numeroColumnas; j++)
matriz [i][j]=0;
}

public Matriz suma(Matriz b){
Matriz resultado;
if((this.numeroFilas == b.numeroFilas)&& (this.numeroColumnas == b.numeroColumnas)){
resultado = new Matriz(this.numeroFilas, this.numeroColumnas);
for(int i=0; i < this.numeroFilas; i++)
for(int j=0; j < this.numeroColumnas; j++)
resultado.matriz[i][j] = this.matriz[i][j]+ b.matriz[i][j];
return resultado;
}
else
System.out.println("ERROR EN DIMENSIONES DE LAS MATRICES");
resultado=null;
return resultado;
}

/**
* Metodo de resta de matrices
* @return matriz resultado de resta
*/
public Matriz resta(Matriz b){
Matriz resultado;
if ((this.numeroFilas == b.numeroFilas)&(this.numeroFilas == b.numeroColumnas)){
resultado = new Matriz (this.numeroFilas,this.numeroColumnas);//construyo la caja donde almaceno el resultado
for(int i = 0;i < this.numeroFilas;i++)
for(int j=0;j < this.numeroColumnas;j++)
resultado.matriz[i][j] = this.matriz[i][j]-b.matriz[i][j];
return resultado;
}

else{
System.out.println("ERROR EN DIMENSIONES DE LAS MATRICES");
resultado=null;
return resultado;
}
}


/**
* Metodo para transpuesta de una matriz
* @return
*/
//el numero de filas se cambia al numero de columnas

public Matriz Transpuesta(){
Matriz resultado;
resultado=new Matriz(this.numeroColumnas,this.numeroFilas);
for(int i=0; i < this.numeroFilas; i++)
for(int j=0; j < this.numeroColumnas; j++)
resultado.matriz[j][i]=this.matriz[i][j];
return resultado;
}

/**
* Metodo para multiplicaci�n entre matrices
* @return
*/
public Matriz Multiplicacion(Matriz b){
Matriz resultado;
if(this.numeroColumnas==b.numeroFilas){
resultado=new Matriz(this.numeroFilas, b.numeroColumnas);
for(int i=0; i < this.numeroFilas; i++){
for(int j=0; j < b.numeroColumnas; j++){
for(int k=0; k < this.numeroColumnas; k++)
resultado.matriz[i][j]+=this.matriz[i][k]*b.matriz[k][j];
}
}
return resultado;
}
else
System.out.println("ERROR EN DIMENSIONES DE LAS MATRICES");
resultado=null;
return resultado;
}

public Matriz Inversa(){
Matriz r;
r=new Matriz(this.numeroColumnas,this.numeroFilas);
for(int i=0; i < this.numeroFilas; i++)
for(int j=0; j < this.numeroColumnas; j++)
r=new Matriz(this.numeroColumnas,this.numeroFilas);
r.matriz[0][0]=((this.matriz[1][1]*this.matriz[2][2])-(this.matriz[2][1]*this.matriz[1][2]));
r.matriz[0][1]=((this.matriz[1][0]*this.matriz[2][2])-(this.matriz[2][0]*this.matriz[1][2]));
r.matriz[0][2]=((this.matriz[1][0]*this.matriz[2][1])-(this.matriz[2][0]*this.matriz[1][1]));
r.matriz[1][0]=((this.matriz[0][1]*this.matriz[2][2])-(this.matriz[2][1]*this.matriz[0][2]));
r.matriz[1][1]=((this.matriz[1][0]*this.matriz[2][2])-(this.matriz[2][0]*this.matriz[1][2]));
r.matriz[1][2]=((this.matriz[0][0]*this.matriz[2][1])-(this.matriz[2][0]*this.matriz[0][1]));
r.matriz[2][0]=((this.matriz[0][1]*this.matriz[1][2])-(this.matriz[1][1]*this.matriz[0][2]));
r.matriz[2][1]=((this.matriz[0][0]*this.matriz[1][2])-(this.matriz[1][0]*this.matriz[0][2]));
r.matriz[2][2]=((this.matriz[0][0]*this.matriz[1][1])-(this.matriz[1][0]*this.matriz[0][1]));
return r;
}


public void leer(){
String aux;
for(int i=0; i < this.numeroFilas; i++){
for(int j=0; j < this.numeroColumnas; j++){
aux = JOptionPane.showInputDialog(null,"INGRESO DE VALORES","INGRESE EL VALOR: "+(i+1)+","+(j+1),JOptionPane.DEFAULT_OPTION);
this.matriz[i][j]=Double.parseDouble(aux);
}
}
}

public String toString(){

String aux="\n";
DecimalFormat df = new DecimalFormat("0.0000");
for(int i=0; i < numeroFilas; i++){
for(int j=0; j < numeroColumnas; j++){
aux+=df.format(matriz[i][j])+" ";
}
aux+="\n";
}
aux+=" ";
return aux;
}
}



// APPLET


public class OperacionesMatrices extends javax.swing.JApplet {


/** Initializes the applet OperacionesMatrices */
public void init() {
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
initComponents();
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}


/** This method is called from within the init() method to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
//
private void initComponents() {


jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jTextField3 = new javax.swing.JTextField();
jTextField4 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jButton4 = new javax.swing.JButton();


jLabel1.setText("Operaciones de Matrices");


jLabel2.setText("Operaciones Binarias");


jLabel3.setText("Matriz 1");


jLabel4.setText("Matriz 2");


jLabel5.setText("Numero de Filas");


jLabel6.setText("Numero de Columnas");


jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});


jTextField2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField2ActionPerformed(evt);
}
});


jLabel7.setText("Numero Filas");


jLabel8.setText("Numero Columnas");


jTextField3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField3ActionPerformed(evt);
}
});


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


jButton2.setText("Resta");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});


jButton3.setText("Multiplicación");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});


jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);


jButton4.setText("Transpuesta");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});


javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(65, 65, 65)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton4)
.addContainerGap())
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jLabel5)
.addComponent(jLabel6)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jButton2)))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jTextField2)
.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel7)
.addComponent(jLabel8)
.addComponent(jLabel4)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(35, 35, 35)
.addComponent(jButton3)))))
.addGap(39, 39, 39)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jTextField3)
.addComponent(jTextField4, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE)))
.addComponent(jLabel2)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 523, Short.MAX_VALUE))
.addGap(22, 22, 22))))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(26, 26, 26)
.addComponent(jLabel2))
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel8))
.addGap(31, 31, 31)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2)
.addComponent(jButton3)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(58, 58, 58)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton4)
.addGap(15, 15, 15)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(57, Short.MAX_VALUE))
);


javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
}//


private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}


private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}


private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}


private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String aux = jTextField1.getText();
String aux1="";
int nF = Integer.parseInt(aux);
aux = jTextField2.getText();
int nC = Integer.parseInt(aux);
m1 = new Matriz(nF,nC);
m1.leer();
aux1 += m1.toString();
aux = jTextField3.getText();
nF = Integer.parseInt(aux);
aux = jTextField4.getText();
nC = Integer.parseInt(aux);
m2 = new Matriz(nF,nC);
m2.leer();
aux1 += m2.toString();
jTextArea1.setText("Suma de Matrices: \n"+aux1+(m1.suma(m2)).toString());
}


private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
String aux = jTextField1.getText();
String aux1="";
int nF = Integer.parseInt(aux);
aux = jTextField2.getText();
int nC = Integer.parseInt(aux);
m1 = new Matriz(nF,nC);
m1.leer();
aux1 += m1.toString();
aux = jTextField3.getText();
nF = Integer.parseInt(aux);
aux = jTextField4.getText();
nC = Integer.parseInt(aux);
m2 = new Matriz(nF,nC);
m2.leer();
aux1 += m2.toString();
jTextArea1.setText("Resta de Matrices: \n"+aux1+(m1.resta(m2)).toString());
}


private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
String aux = jTextField1.getText();
String aux1="";
int nF = Integer.parseInt(aux);
aux = jTextField2.getText();
int nC = Integer.parseInt(aux);
m1 = new Matriz(nF,nC);
m1.leer();
aux1 += m1.toString();
aux = jTextField3.getText();
nF = Integer.parseInt(aux);
aux = jTextField4.getText();
nC = Integer.parseInt(aux);
m2 = new Matriz(nF,nC);
m2.leer();
aux1 += m2.toString();
jTextArea1.setText("Multiplicacion de Matrices: \n"+aux1+(m1.Multiplicacion(m2)).toString());
}


private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
String aux = jTextField1.getText();
String aux1="";
int nF = Integer.parseInt(aux);
aux = jTextField2.getText();
int nC = Integer.parseInt(aux);
m1 = new Matriz(nF,nC);
m1.leer();
aux1+= m1.toString();
jTextArea1.setText("Transpuesta de Matrices: \n"+aux1+(m1.Transpuesta()).toString());






// TODO add your handling code here:
}


public Matriz m1;
public Matriz m2;
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
// End of variables declaration


}

martes, 1 de diciembre de 2009

Applet 1 (Suma de dos Matrices)

//MATRIZ

import javax.swing.JOptionPane;

public class Matriz {
public int numeroFilas;
public int numeroColumnas;
public double [][]matriz;

/**
* constructor sin parametros
*/
public Matriz(){//arreglo de filas y columnas
}

/**
* Constructor de parametros
* @param nF numero de Filas
* @param nC numero de Columnas
*/

public Matriz(int nF, int nC){

numeroFilas=nF;
numeroColumnas=nC;
matriz=new double[numeroFilas][numeroColumnas];//construyo un sitio para almacenar ceros
for(int i=0;i < numeroFilas;i++)
for(int j=0; j < numeroColumnas; j++)
matriz [i][j]=0;
}

/**
* Metodo de suma de matrices
* @param B primer sumando
* @return matriz resultado de suma
*/
public Matriz suma(Matriz b){
Matriz resultado;
//probar q el numero de fila y columnas de la primera matriz sea = al numero de
//filas y columnas de la segunda
//this referencia a un objeto que aun no esta creado pero que alguien algun momento lo va a crear
if((this.numeroFilas == b.numeroFilas)&& (this.numeroColumnas == b.numeroColumnas)){
resultado = new Matriz(this.numeroFilas, this.numeroColumnas);
for(int i=0; i < this.numeroFilas; i++)
for(int j=0; j < this.numeroColumnas; j++)
resultado.matriz[i][j] = this.matriz[i][j]+ b.matriz[i][j];
return resultado;
}
else
System.out.println("ERROR EN DIMENSIONES DE LAS MATRICES");
resultado=null;
return resultado;
}

/**
* Metodo de resta de matrices
* @return matriz resultado de resta
*/
public Matriz resta(Matriz b){
Matriz resultado;


if ((this.numeroFilas == b.numeroFilas)&(this.numeroFilas == b.numeroColumnas)){
resultado = new Matriz (this.numeroFilas,this.numeroColumnas);//construyo la caja donde almaceno el resultado
for(int i = 0;i < this.numeroFilas;i++)
for(int j=0;j < this.numeroColumnas;j++)
resultado.matriz[i][j] = this.matriz[i][j]-b.matriz[i][j];
return resultado;
}

else{
System.out.println("ERROR EN DIMENSIONES DE LAS MATRICES");
resultado=null;
return resultado;
}
}


/**
* Metodo para transpuesta de una matriz
* @return
*/
//el numero de filas se cambia al numero de columnas

public Matriz Transpuesta(){
Matriz resultado;
resultado=new Matriz(this.numeroColumnas,this.numeroFilas);
for(int i=0; i < this.numeroFilas; i++)
for(int j=0; j < this.numeroColumnas; j++)
resultado.matriz[j][i]=this.matriz[i][j];
return resultado;
}

/**
* Metodo para multiplicaci�n entre matrices
* @return
*/
public Matriz Multiplicacion(Matriz b){
Matriz resultado;
if(this.numeroColumnas==b.numeroFilas){
resultado=new Matriz(this.numeroFilas, b.numeroColumnas);
for(int i=0; i < this.numeroFilas; i++){
for(int j=0; j < b.numeroColumnas; j++){
for(int k=0; k < this.numeroColumnas; k++)
resultado.matriz[i][j]+=this.matriz[i][k]*b.matriz[k][j];
}
}
return resultado;
}
else
System.out.println("ERROR EN DIMENSIONES DE LAS MATRICES");
resultado=null;
return resultado;
}

public void leer(){
String aux;
for(int i=0; i < this.numeroFilas; i++){
for(int j=0; j < this.numeroColumnas; j++){
aux = JOptionPane.showInputDialog(null,"INGRESO DE VALORES","INGRESE EL VALOR: "+(i+1)+","+(j+1),JOptionPane.DEFAULT_OPTION);
this.matriz[i][j]=Double.parseDouble(aux);
}
}
}


/**
* Devuelve el objeto matriz en texto
* @return
*/
public String toString(){
String aux="\n\n";
for(int i=0; i < numeroFilas; i++){
for(int j=0; j < numeroColumnas; j++){
aux+=matriz[i][j]+" ";
}
aux+="\n";
}
aux+=" ";
return aux;
}
}


//APPLET
public class AppletSumMat extends javax.swing.JApplet {

/** Initializes the applet Applet2 */
public void init() {
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
initComponents();
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}

/** This method is called from within the init() method to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
//
private void initComponents() {

jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jLabel4 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jButton3 = new javax.swing.JButton();
jTextField3 = new javax.swing.JTextField();
jTextField4 = new javax.swing.JTextField();
jScrollPane2 = new javax.swing.JScrollPane();
jTextArea2 = new javax.swing.JTextArea();
jScrollPane3 = new javax.swing.JScrollPane();
jTextArea3 = new javax.swing.JTextArea();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();

jLabel1.setFont(new java.awt.Font("Arial", 0, 14));
jLabel1.setForeground(new java.awt.Color(51, 102, 0));
jLabel1.setText("Suma de dos Matrices");

jLabel2.setText("Numero de filas Matriz1");

jLabel3.setText("Numero de columnas Matriz1");

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

jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});

jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);

jLabel4.setText("Suma de Matriz 1 y 2");

jButton2.setText("Imprimir");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

jLabel5.setText("Numero de filas Matriz2");

jLabel6.setText("Numero de columnas Matriz2");

jButton3.setText("Leer");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});

jTextArea2.setColumns(20);
jTextArea2.setRows(5);
jScrollPane2.setViewportView(jTextArea2);

jTextArea3.setColumns(20);
jTextArea3.setRows(5);
jScrollPane3.setViewportView(jTextArea3);

jButton4.setText("Imprimir");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});

jButton5.setText("Imprimir");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});

jLabel7.setText("Matriz 1 ");

jLabel8.setText("Matriz 2 ");

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel3))
.addGap(24, 24, 24)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jTextField1)
.addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE)))
.addComponent(jButton1)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel7)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(120, 120, 120)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel5)
.addComponent(jLabel6))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jTextField3, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 74, Short.MAX_VALUE)))
.addComponent(jButton3)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel8)
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(235, 235, 235)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(39, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(173, Short.MAX_VALUE)
.addComponent(jButton4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(239, 239, 239))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(2, 2, 2)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton1))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel6)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel7)
.addComponent(jLabel8))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton2)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton5)
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(28, 28, 28)
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton4))
.addGap(77, 77, 77))
);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 489, Short.MAX_VALUE)
);
}//

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String aux = jTextField1.getText();
nF = Integer.parseInt(aux);
aux = jTextField2.getText();
nC = Integer.parseInt(aux);
m = new Matriz(nF,nC);
m.leer();
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:

jTextArea2.setText(m.toString());

}

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
String aux = jTextField3.getText();
nF = Integer.parseInt(aux);
aux = jTextField4.getText();
nC = Integer.parseInt(aux);
s = new Matriz(nF,nC);
s.leer(); // TODO add your handling code here:
}

private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
T = new Matriz(nF,nC);
T = m.suma(s);
jTextArea1.setText(T.toString()); // TODO add your handling code here:
}

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
jTextArea3.setText(s.toString()); // TODO add your handling code here:
}


// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextArea jTextArea2;
private javax.swing.JTextArea jTextArea3;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
// End of variables declaration

public int nF;
public int nC;
public Matriz m;
public Matriz s;
public Matriz T;
}

//RESULTADO DEL PROGRAMA