sábado, 9 de enero de 2010

sensor temperatura

sensor

public class Interfase extends JFrame{
public Interfase(){
super("monitoreo temperatura");
setSize(900,500);
show();
}
public void paint(Graphics g){
super.paint(g);
g.setColor(Color.BLUE);
g.drawOval(200,200,200,200);
g.setColor(Color.black);
g.drawString("180 ºC ", 150, 250);
g.drawString("0 ºC", 150, 100);
Sensor s = new Sensor();
s.leerTemp();

if(s.getTemp() >0 & s.getTemp()<=120){
g.setColor(Color.ORANGE);
g.fillArc(200, 200, 200, 200, 90,s.getTemp());
g.drawString(s.getTemp()+" ºC", 60, 160);
}

if(s.getTemp() >=120 & s.getTemp()<240){
g.setColor(Color.YELLOW);
g.fillArc(200, 200, 200, 200, 90,s.getTemp());
g.drawString(s.getTemp()+" ºC", 75, 200-s.getTemp());
}

if(s.getTemp() >=240 & s.getTemp()<360){
g.setColor(Color.WHITE);
g.fillArc(200, 200, 200, 200, 90,s.getTemp());
g.drawString(s.getTemp()+" ºC", 75, 200-s.getTemp());
}
}
public static void main(String args[]){
Interfase in =new Interfase();
in.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}
}

***********************

public class Sensor {
private int temp;
public Sensor(){

}
public void setTmp(int t){
temp=t;

}
public int getTemp(){
return temp;
}
public void leerTemp(){
String aux;
aux = JOptionPane.showInputDialog("valor temperatura=");
temp = Integer.parseInt(aux);
}
public static void main(String args[]){
Sensor s = new Sensor();
System.out.println("Temperatura = "+s.getTemp());
}

}

domingo, 20 de diciembre de 2009

CALCU

CALCULATOR
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 raiz(double x){
if(x > = 0){
resultado = Math.sqrt(x);
}else{
System.out.println("Solo valores postivos");
resultado = 0;
}
return resultado;

}
public static double logaritmo (double x){
resultado = Math.log(x);
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 double exponente (double x,double y){
resultado = Math.pow(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);
}

}

APPLET
public class OperacionesCalculadora extends javax.swing.JApplet {
public void init() {
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
initComponents();
}});
} catch (Exception ex) {
ex.printStackTrace();
}}


private void initComponents() {

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();
jButton17 = new javax.swing.JButton();
jButton18 = new javax.swing.JButton();
jButton19 = new javax.swing.JButton();
jButton20 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jTextField1 = new javax.swing.JTextField();
jButton21 = new javax.swing.JButton();
jButton22 = new javax.swing.JButton();

jButton1.setBackground(new java.awt.Color(204, 0, 204));
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("logaritmo");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});

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

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

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

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

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

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

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

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

jButton14.setText("9");
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);
}
});

jButton17.setText("-");
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);
}
});

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

jButton21.setText("=");
jButton21.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton21ActionPerformed(evt);
}
});

jButton22.setText("borrar");
jButton22.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton22ActionPerformed(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()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton6))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton7))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton4)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jButton5, 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)))
.addGap(37, 37, 37)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jButton12)
.addComponent(jButton21))))
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton8)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton9))
.addGroup(layout.createSequentialGroup()
.addComponent(jButton10)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton11))
.addGroup(layout.createSequentialGroup()
.addComponent(jButton13)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton14))
.addComponent(jButton15)
.addComponent(jButton22))
.addGap(52, 52, 52)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jButton16, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton17, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton18, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton19, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton20, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addContainerGap(33, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton16)
.addComponent(jButton6)
.addComponent(jButton8)
.addComponent(jButton9)
.addComponent(jButton1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton17)
.addComponent(jButton7)
.addComponent(jButton10)
.addComponent(jButton11)
.addComponent(jButton2))
.addGap(6, 6, 6)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton18)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton19)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton20))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton3)
.addComponent(jButton12)
.addComponent(jButton13)
.addComponent(jButton14))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton5))
.addComponent(jButton15))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(26, 26, 26))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton21)
.addComponent(jButton22))
.addGap(140, 140, 140))))
);
}//

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
String aux1 = jTextField1.getText();
double r = Double.parseDouble(aux1);
r = Operaciones.coseno(r);
jTextArea1.setText("El coseno es :\n "+r);
aux = "";
jTextField1.setText(aux);
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String aux1 = jTextField1.getText();
double r = Double.parseDouble(aux1);
r = Operaciones.seno(r);
jTextArea1.setText("El seno es :\n "+r);
aux = "";
jTextField1.setText(aux);
}

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
aux += 1;
jTextField1.setText(aux);
}

private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {

aux += 2;
jTextField1.setText(aux);
}

private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {
aux += 3;
jTextField1.setText(aux);
}

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
aux += 4;
jTextField1.setText(aux);
}

private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {
aux += 5;
jTextField1.setText(aux);
}

private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {
aux += 6;
jTextField1.setText(aux);
}

private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {
aux += 7;
jTextField1.setText(aux);
}

private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {
aux += 8;
jTextField1.setText(aux);
}

private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {
aux += 9;
jTextField1.setText(aux);
}

private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {
aux += 0;
jTextField1.setText(aux);
}

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
String aux1 = jTextField1.getText();
double r = Double.parseDouble(aux1);
r = Operaciones.tangente(r);
jTextArea1.setText("La tangente es :\n "+r);
aux = "";
jTextField1.setText(aux);
}

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
String aux1 = jTextField1.getText();
double r = Double.parseDouble(aux1);
r = Operaciones.raiz(r);
jTextArea1.setText("La raiz es :\n "+r);
aux = "";
jTextField1.setText(aux);
}

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
String aux1 = jTextField1.getText();
double r = Double.parseDouble(aux1);
r = Operaciones.logaritmo(r);
jTextArea1.setText("El logaritmo es :\n "+r);
aux = "";
jTextField1.setText(aux);
}

private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) {
String aux1 = jTextField1.getText();
x = Double.parseDouble(aux1);
aux2 = "+";
aux="";
jTextField1.setText("");
}

private void jButton17ActionPerformed(java.awt.event.ActionEvent evt) {
String aux1 = jTextField1.getText();
x = Double.parseDouble(aux1);
aux2 = "-";
aux="";
jTextField1.setText("");
}

private void jButton18ActionPerformed(java.awt.event.ActionEvent evt) {
String aux1 = jTextField1.getText();
x = Double.parseDouble(aux1);
aux2 = "^";
aux="";
jTextField1.setText("");
}

private void jButton19ActionPerformed(java.awt.event.ActionEvent evt) {
String aux1 = jTextField1.getText();
x = Double.parseDouble(aux1);
aux2 = "*";
aux="";
jTextField1.setText("");
}

private void jButton20ActionPerformed(java.awt.event.ActionEvent evt) {
String aux1 = jTextField1.getText();
x = Double.parseDouble(aux1);
aux2 = "/";
aux="";
jTextField1.setText("");
}

private void jButton21ActionPerformed(java.awt.event.ActionEvent evt) {
if(aux2 == "+"){
String aux1 = jTextField1.getText();
double r = Double.parseDouble(aux1);
jTextArea1.setText("La suma es: \n" +Operaciones.suma(x, r));
}

if(aux2 == "-"){
String aux1 = jTextField1.getText();
double r = Double.parseDouble(aux1);
jTextArea1.setText("La resta es:\n" +Operaciones.resta(x,r));
}

if(aux2 == "^"){
String aux1 = jTextField1.getText();
double r = Double.parseDouble(aux1);
jTextArea1.setText("La potencia es:\n" +Operaciones.exponente(x, r));
}

if(aux2 == "*"){
String aux1 = jTextField1.getText();
double r = Double.parseDouble(aux1);
jTextArea1.setText("La multiplicacion es:\n" +Operaciones.multiplicacion(x, r));
}

if(aux2 == "/"){
String aux1 = jTextField1.getText();
double r = Double.parseDouble(aux1);
jTextArea1.setText("La division es:\n" +Operaciones.division(x,r));
}
}

private void jButton22ActionPerformed(java.awt.event.ActionEvent evt) {
aux="";
jTextField1.setText("");
}

public String aux = "";
public String aux2 = "";
double x;
// 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 jButton21;
private javax.swing.JButton jButton22;
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.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField jTextField1;

}

martes, 8 de diciembre de 2009

MATRICES OPERACIONES

BINARIAS Y UNITARIAS
MATRIZ

import javax.swing.JOptionPane;
import java.text.DecimalFormat;

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

public Matriz(){//arreglo de filas y columnas
}

public Matriz(int nF, int nC){

numeroFilas=nF;
numeroColumnas=nC;
matriz=new double[numeroFilas][numeroColumnasfor(int i=0;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 DIMENSIONES ");
resultado=null;
return resultado;
}


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
for(int j=0;j
resultado.matriz[i][j] = this.matriz[i][j]-b.matriz[i][j];
return resultado;
}

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

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;
}


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 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 DIMENSIONES ");
resultado=null;
return resultado;
}

public void leerMatriz(){
int i;
for(i=0;i
for(int j=0;j
String aux;
aux=JOptionPane.showInputDialog(null,"Ingreso de valores",
"Ingreseel Valor "+"["+(i+1)+","+(j+1)+"]",JOptionPane.DEFAULT_OPTION);
this.matriz[i][j]=Double.parseDouble(aux);
}
}
}


public String toString(){
String aux="\n\n";
DecimalFormat df = new DecimalFormat("0.0000");//# enteros y # decimales
for(int i=0; i
for(int j=0; j
aux+=df.format(matriz[i][j])+" ";
}
aux+="\n";
}
aux+=" ";
return aux;
}

}

OPERACIONES MATRICES

public class OperacionesMatrices extends javax.swing.JApplet {


public void init() {
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
initComponents();
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}

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();
jSeparator1 = new javax.swing.JSeparator();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
jTextField5 = new javax.swing.JTextField();
jTextField6 = new javax.swing.JTextField();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jScrollPane2 = new javax.swing.JScrollPane();
jTextArea2 = new javax.swing.JTextArea();

jLabel1.setForeground(new java.awt.Color(255, 51, 153));
jLabel1.setText("OPERACION MATRIZ");

jLabel2.setText("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);
}
});

jLabel7.setText("Numero de Filas");

jLabel8.setText("Numero de 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("Multiplicacion");
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);

jLabel9.setText("Operaciones Unitarias:");

jLabel10.setText("Numero de Filas:");

jLabel11.setText("Numero de Columnas:");

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

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

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

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

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(335, Short.MAX_VALUE)
.addComponent(jLabel1)
.addGap(243, 243, 243))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(123, 123, 123)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel3)
.addComponent(jLabel2))
.addGap(211, 211, 211)
.addComponent(jLabel4)
.addContainerGap(244, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(161, 161, 161)
.addComponent(jButton1)
.addGap(69, 69, 69)
.addComponent(jButton2)
.addGap(56, 56, 56)
.addComponent(jButton3)
.addContainerGap(219, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 374, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(105, 105, 105)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel5)
.addGap(34, 34, 34)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(64, 64, 64)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel7)
.addComponent(jLabel8))
.addGap(31, 31, 31)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField4, javax.swing.GroupLayout.DEFAULT_SIZE, 64, Short.MAX_VALUE)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap(184, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 700, Short.MAX_VALUE)
.addContainerGap())
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(104, 104, 104)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(44, 44, 44)
.addComponent(jLabel10)
.addGap(18, 18, 18)
.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(32, 32, 32)
.addComponent(jLabel11)
.addGap(29, 29, 29)
.addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel9))
.addContainerGap(197, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(192, 192, 192)
.addComponent(jButton4)
.addGap(115, 115, 115)
.addComponent(jButton5)
.addContainerGap(251, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(256, 256, 256)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(276, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(26, 26, 26)
.addComponent(jLabel1)
.addGap(28, 28, 28)
.addComponent(jLabel2)
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jLabel4))
.addGap(16, 16, 16)
.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)
.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.TRAILING)
.addComponent(jLabel6)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel8)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(34, 34, 34)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2)
.addComponent(jButton3))
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel9)
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel10)
.addComponent(jLabel11)
.addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(28, 28, 28)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton4)
.addComponent(jButton5))
.addGap(27, 27, 27)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE)
.addContainerGap())
);

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 jTextField1ActionPerformed(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 jButton3ActionPerformed(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.leerMatriz();
//aux1+= m1.toString();

aux = jTextField3.getText();
nF = Integer.parseInt(aux);
aux = jTextField4.getText();
nC=Integer.parseInt(aux);
m2 = new Matriz (nF,nC);
m2.leerMatriz();
//aux1 += m2.toString();
jTextArea1.setText("\nMATRIZ 1: \n"+(m1.toString())+"\nMATRIZ 2: \n"+(m2.toString())+"\nMULTIPLICACION DE MATRICES: \n"+(m1.Multiplicacion(m2)).toString());
}

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.leerMatriz();
//aux1+= m1.toString();


aux = jTextField3.getText();
nF = Integer.parseInt(aux);
aux = jTextField4.getText();
nC=Integer.parseInt(aux);
m2 = new Matriz (nF,nC);
m2.leerMatriz();
//aux1 += m2.toString();
jTextArea1.setText("\nMATRIZ 1: \n"+(m1.toString())+"\nMATRIZ 2: \n"+(m2.toString())+"\nSUMA DE MATRICES: \n"+(m1.suma(m2)).toString());



}

private void jButton2ActionPerformed(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.leerMatriz();
//aux1+= m1.toString();

aux = jTextField3.getText();
nF = Integer.parseInt(aux);
aux = jTextField4.getText();
nC=Integer.parseInt(aux);
m2 = new Matriz (nF,nC);
m2.leerMatriz();

jTextArea1.setText("\nMATRIZ 1: \n"+(m1.toString())+"\nMATRIZ 2: \n"+(m2.toString())+"\nRESTA DE MATRICES: \n"+(m1.resta(m2)).toString());

}

private void jTextField6ActionPerformed(java.awt.event.ActionEvent evt) {
}

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
String aux = jTextField5.getText();//captura el texto y lo almacena en variable aux aparec en el boton jtex field 1
int nF = Integer.parseInt(aux);//num. filas --->CONVIERTO DE STRING A NUMERO ENTERO
aux = jTextField6.getText();
int nC = Integer.parseInt(aux);//num columnas
m3= new Matriz(nF,nC);
m3.leerMatriz();//ingreso de datos
jTextArea2.setText("\nMATRIZ: \n"+(m3.toString())+"INVERSA DE MATRICES: \n"+(m3.Inversa().toString()));
}

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {

String aux = jTextField5.getText();//captura el texto y lo almacena en variable aux aparec en el boton jtex field 1
int nF = Integer.parseInt(aux);//num. filas --->CONVIERTO DE STRING A NUMERO ENTERO
aux = jTextField6.getText();
int nC = Integer.parseInt(aux);//num columnas
m3= new Matriz(nF,nC);
m3.leerMatriz();//ingreso de datos

jTextArea2.setText("\nMATRIZ: \n"+(m3.toString())+"TRANSPUESTA DE MATRIZ: \n"+(m3.Transpuesta().toString()));
}
public Matriz m1;
public Matriz m2;

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 jLabel10;
private javax.swing.JLabel jLabel11;
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.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextArea jTextArea2;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private javax.swing.JTextField jTextField5;
private javax.swing.JTextField jTextField6;
public Matriz m3;
}

martes, 1 de diciembre de 2009

APPETS

Applet operaciones Matrices


public class OperacionesMatrice extends javax.swing.JApplet {

public void init() {
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
initComponents();
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}

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();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
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 Matrices");

jLabel2.setText("Operaciones Binarias");

jLabel3.setText("Matriz 1");

jLabel4.setText("Matriz 2");

jLabel5.setText("Número de Filas");

jLabel6.setText("Nínaero de columnas");

jLabel7.setText("Número de filas");

jLabel8.setText("Número de columnas");

jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(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()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addGap(27, 27, 27)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 458, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(jLabel3))
.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.LEADING, false)
.addComponent(jTextField2)
.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 66, Short.MAX_VALUE)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton2)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 29, Short.MAX_VALUE)
.addComponent(jButton3)
.addGap(30, 30, 30)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel8)
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jTextField3)
.addComponent(jTextField4, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE)))
.addComponent(jButton4)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 61, Short.MAX_VALUE))
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 558, Short.MAX_VALUE))
.addGap(42, 42, 42))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addGap(177, 177, 177)
.addComponent(jLabel1)))
.addGap(42, 42, 42))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel2)
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jLabel4))
.addGap(18, 18, 18)
.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(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.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(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel8))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton3)
.addComponent(jButton2)
.addComponent(jButton4)
.addComponent(jButton1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 281, Short.MAX_VALUE)
.addContainerGap())
);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(120, 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 jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void jButton3ActionPerformed(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 Matriz1(nF,nC);
m1.leer();
aux1 += m1.toString();
aux = jTextField3.getText();
int nuF = Integer.parseInt(aux);
aux = jTextField4.getText();
int nuC = Integer.parseInt(aux);
m2 = new Matriz1(nuF,nuC);
m2.leer();
aux1 += m2.toString();
if(nC==nuF)
{
jTextArea1.setText("Matrices: \n"+aux1+"\nMultiplicacion de Matrices"+(m1.multiplicacion(m2)).toString());
}
else
{
jTextArea1.setText("Error en las dimensiones de las Matrices");
}
}

martes, 24 de noviembre de 2009

APPLETS

Qué son los Applets de Java

Una manera de incluir programas complejos en el ámbito de una página web. Estos applets se programan en Java y por tanto se benefician de la potencia de este lenguaje para la Red.
Por Miguel Angel Alvarez
Un applet no es más que una aplicación Java que se encuentra en web. El applet presenta unas diferencias con las aplicaciones porque no tienen ningún main, y son clases que tienen el mismo nombre que el del archivo que las incluye, que amplían la clase Applet del paquete java.applet.
Incluso para los applets existe la versión JApplet de swing, que se utiliza para introducir componentes Swing en lugar de componentes AWT. Un applet necesita un archivo html que lo invoque. Por ejemplo, PrimoApplet.java, el applet que queremos poner en marcha, lo redactamos y el compilador genera PrimoApplet.class. Para ponerlo en marcha necesitamos un archivo html que incluya el TAG en su interior:

Si este archivo se llama tribilín.html, llegados a este punto tenemos dos posibilidades para poner en marcha el applet. La primera, en fase debug, es utilizar el programa appletviewer de JDK y, para esto, tendremos que escribir partiendo del prompt de dos:
appletviewer tribilín.html
La segunda es utilizar un web browser, como Explorer o Netscape invocando el archivo tribilín.html.
Como se puede ver, se pone en marcha siempre el archivo html, y no el archivo .class como ocurría para las aplicaciones. Es el archivo html el que invoca la aplicación .java.
Para más informaciones sobre las páginas html os aconsejo visitar el sito HTMLpoint donde se encuentran apartados que tratan este tema. Nosostros prepararemos unas páginas sencillas que sirven sólo para cargar nuestros applets. por ejemplo, para el applet PrimoApplet.class de antes, el archivo tribilín.html será algo parecido a:


Applet PrimoApplet <br /></head> <br /><body> <br />El siguiente es el applet PrimoApplet.class <br /><applet code="PrimoApplet.class" width=100 height=100>¡Tu browser es viejo, tienes que cambiarlo!</APPLET> <br /></body> <br /></html> <br />Ciclo de vida de un applet <br />Para seguir el ciclo de vida de un applet, supondremos que estamos ejecutando en nuestro navegador el applet básico HolaMundo, a través de la página HTML que lo carga y corre. <br /> <br />Lo primero que aparece son los mensajes "initializing... starting...", como resultado de la carga del applet en el navegador. Una vez cargado, lo que sucede es: <br /> <br /> <br /> <br />Se crea una instancia de la clase que controla al applet <br />El applet se inicializa a si mismo <br />Comienza la ejecución del applet <br /> <br />Cuando se abandona la página, por ejemplo, para ir a la siguiente, el applet detiene la ejecución. Cuando se regresa a la página que contiene el applet, se reanuda la ejecución. <br /> <br />Si se utiliza la opción del navegador de Reload, es decir, volver a cargar la página, el applet es descargado y vuelto a cargar. El applet libera todos los recursos que hubiese acaparado, detiene su ejecución y ejecuta su finalizador para realizar un proceso de limpieza final de sus trazas. Después de esto, el applet se descarga de la memoria y vuelve a cargarse volviendo a comenzar su inicialización. <br /> <br />Finalmente, cuando se concluye la ejecución del navegador, o de la aplicación que está visualizando el applet, se detiene la ejecución del applet y se libera toda la memoria y recursos ocupados por el applet antes de salir del navegador. <br /> <br /> <br />Autor: htmlpoint <br />http://www.htmlpoint.com/guidajava/java_18.htm <br />Agustín Froufe. <br />Extraido de: http://www.publispain.com/supertutoriales/ <br /> <div style='clear: both;'></div> </div> <div class='post-footer'> <div class='post-footer-line post-footer-line-1'> <span class='post-author vcard'> Publicado por <span class='fn' itemprop='author' itemscope='itemscope' itemtype='http://schema.org/Person'> <meta content='https://www.blogger.com/profile/11274018804682176170' itemprop='url'/> <a class='g-profile' href='https://www.blogger.com/profile/11274018804682176170' rel='author' title='author profile'> <span itemprop='name'>jasg587</span> </a> </span> </span> <span class='post-timestamp'> en <meta content='http://jasg587.blogspot.com/2009/11/applets.html' itemprop='url'/> <a class='timestamp-link' href='https://jasg587.blogspot.com/2009/11/applets.html' rel='bookmark' title='permanent link'><abbr class='published' itemprop='datePublished' title='2009-11-24T17:26:00-08:00'>17:26</abbr></a> </span> <span class='post-comment-link'> <a class='comment-link' href='https://jasg587.blogspot.com/2009/11/applets.html#comment-form' onclick=''> No hay comentarios: </a> </span> <span class='post-icons'> <span class='item-action'> <a href='https://www.blogger.com/email-post/524931798993985876/2067053675507371533' title='Enviar entrada por correo electrónico'> <img alt='' class='icon-action' height='13' src='https://resources.blogblog.com/img/icon18_email.gif' width='18'/> </a> </span> <span class='item-control blog-admin pid-844765198'> <a href='https://www.blogger.com/post-edit.g?blogID=524931798993985876&postID=2067053675507371533&from=pencil' title='Editar entrada'> <img alt='' class='icon-action' height='18' src='https://resources.blogblog.com/img/icon18_edit_allbkg.gif' width='18'/> </a> </span> </span> <div class='post-share-buttons goog-inline-block'> </div> </div> <div class='post-footer-line post-footer-line-2'> <span class='post-labels'> </span> </div> <div class='post-footer-line post-footer-line-3'> <span class='post-location'> </span> </div> </div> </div> </div> </div></div> <div class="date-outer"> <h2 class='date-header'><span>lunes, 23 de noviembre de 2009</span></h2> <div class="date-posts"> <div class='post-outer'> <div class='post hentry uncustomized-post-template' itemprop='blogPost' itemscope='itemscope' itemtype='http://schema.org/BlogPosting'> <meta content='524931798993985876' itemprop='blogId'/> <meta content='4307639349724912196' itemprop='postId'/> <a name='4307639349724912196'></a> <h3 class='post-title entry-title' itemprop='name'> <a href='https://jasg587.blogspot.com/2009/11/mruv.html'>MRUV</a> </h3> <div class='post-header'> <div class='post-header-line-1'></div> </div> <div class='post-body entry-content' id='post-body-4307639349724912196' itemprop='description articleBody'> M.R.U.V.<br />MATRIZ<br />public class Matriz {<br />public int numeroFilas;<br />public int numeroColumnas;<br />public double [][]matriz;<br /><br />public Matriz(){<br />}<br /><br />public Matriz(int nF, int nC){<br />numeroFilas = nF;<br />numeroColumnas = nC;<br />matriz = new double [numeroFilas][numeroColumnas];<br /><br />for(int i=0; i < numeroFilas; i++)<br />for(int j=0; j < numeroColumnas; j++)<br />matriz[i][j]=0;<br />}<br />public Matriz suma(Matriz b){<br />Matriz resultado;<br />if((this.numeroFilas == b.numeroFilas)&& (this.numeroColumnas == b.numeroColumnas)){<br />resultado = new Matriz(this.numeroFilas, this.numeroColumnas);<br />for(int i=0; i < this.numeroFilas; i++)<br />for(int j=0; j < this.numeroColumnas; j++)<br />resultado.matriz[i][j] = this.matriz[i][j]+ b.matriz[i][j];<br />return resultado;<br />}<br />else<br />System.out.println("DIMENSIONES ERRADAS");<br />resultado=null;<br />return resultado;<br />}<br />public Matriz multiplicacion(Matriz b){<br />Matriz resultado;<br />if((this.numeroFilas == b.numeroColumnas)){<br />resultado = new Matriz(this.numeroFilas, this.numeroColumnas);<br />for(int i=0; i < this.numeroFilas; i++){<br />for(int j=0; j < b.numeroColumnas; j++){<br />for(int k=0; k < this.numeroColumnas; k++)<br />resultado.matriz[i][j]+=this.matriz[i][k]*b.matriz[k][j];<br />}<br />}<br />return resultado;<br />}<br />else<br />System.out.println("DIMENSIONES ERRADAS ");<br />resultado=null;<br />return resultado;<br />}<br />public String toString(){<br />String aux="\n[\n";<br />for(int i=0; i < numeroFilas; i++){<br />for(int j=0; j < numeroColumnas; j++){<br />aux += matriz[i][j]+" ";<br />}<br />aux+="\n";<br />}<br />aux+= "]";<br />return aux;<br />}<br /><br /><br />}<br /><br /><br /> VECTOR<br />public class Vector3D extends Matriz {<br />double coordenadaX;<br />double coordenadaY;<br />double coordenadaZ;<br /><br />public Vector3D(){<br />super(1,3);<br />}<br /><br />public Vector3D(double x, double y, double z){<br />super(1,3);<br />this.matriz[0][0] = x;<br />this.matriz[0][1] = y;<br />this.matriz[0][2] = z;<br />coordenadaX = x;<br />coordenadaY = y;<br />coordenadaZ = z;<br />}<br /><br />public double magnitud(){<br />double resultado = 0;<br />for(int i=0; i < 3; i++){<br />resultado += this.matriz[0][i]*this.matriz[0][i];<br />}<br />resultado = Math.sqrt;<br />return resultado;<br />}<br />public double magnitud1(){<br />double resultado;<br />resultado = this.coordenadaX*this.coordenadaX+this.coordenadaY*this.coordenadaY+this.coordenadaZ*this.coordenadaZ;<br />resultado = Math.sqrt(resultado);<br />return resultado;<br />}<br />public double magnitud2(){<br />double resultado;<br />resultado = Math.pow(this.coordenadaX, 2)+Math.pow(this.coordenadaY, 2)+Math.pow(this.coordenadaZ, 2);<br />resultado = Math.sqrt(resultado);<br />return resultado;<br />}<br />public Vector3D unitario(){<br />Vector3D unitario = new Vector3D();<br />for(int i=0; i < 3; i++)<br />unitario.matriz[0][i] = this.matriz[0][i]/this.magnitud2();<br />return unitario;<br />}<br />public double productoEscalar(Vector3D v){<br />double resultado = 0;<br />for(int i=0; i < 3; i++)<br />resultado += this.matriz[0][i]*v.matriz[0][i];<br />return resultado;<br />}<br />public Vector3D productoEscalarVector(double a){<br />Vector3D resultado = new Vector3D();<br />for(int i=0; i < 3; i++)<br />resultado.matriz[0][i] = this.matriz[0][i]*a;<br />return resultado;<br />}<br />public Vector3D productoCruz(Vector3D v){<br />Vector3D resultado;<br />resultado = new Vector3D();<br />resultado.matriz[0][0] = this.matriz[0][1]*v.matriz[0][2]-this.matriz[0][2]*v.matriz[0][1];<br />resultado.matriz[0][1] = this.matriz[0][2]*v.matriz[0][0]-this.matriz[0][0]*v.matriz[0][2];<br />resultado.matriz[0][2] = this.matriz[0][0]*v.matriz[0][1]-this.matriz[0][1]*v.matriz[0][0];<br />return resultado;<br />}<br />public static void main(String args[]){<br />Vector3D v1 = new Vector3D(-1,1,-1);<br />Vector3D v2 = new Vector3D(0,2,0);<br />System.out.println(v1+"\n"+v2);<br />System.out.println("COORDENADA X =: "+v1.coordenadaX);<br />System.out.println("\n SUMA DE VECTORES = "+(v1.suma(v2)));<br />System.out.println("\n MAGNITUD VECTOR = "+v1.magnitud());<br />System.out.println("\n MAGNITUD VECTOR = "+v1.magnitud1());<br />System.out.println("\n MAGNITUD VECTOR = "+v1.magnitud2());<br />System.out.println("\n VECTOR UNITARIO = "+v1.unitario());<br />System.out.println("\n PRODUCTO ESCALAR ENTRE VECTORES = "+v1.productoEscalar(v2));<br />System.out.println("\n PRODUCTO CRUZ ENTRE VECTORES = "+v1.productoCruz(v2));<br />}<br />}<br /> MRUV<br />public class MRUV extends Vector3D{<br />Matriz posicion;<br />Matriz velocidad;<br />Matriz aceleracion;<br />Matriz desplazamiento;<br />Matriz velocidad2;<br /><br />public MRUV(){<br />}<br /><br />public MRUV (Vector3D pos, Vector3D vel0, Vector3D ace, Vector3D des){<br />posicion = pos;<br />velocidad = vel0;<br />aceleracion = ace;<br />desplazamiento = des;<br />}<br />public void calcularPosicion(Vector3D ro, Vector3D vel0, Vector3D ace, double t){<br />posicion = ro.suma((vel0.productoEscalarVector(t)).suma((ace.productoEscalarVector(Math.pow(t,2))).productoEscalarVector(1/2)));<br />}<br />public void calcularVelocidad(Vector3D vel0, double t, Vector3D ace){<br />velocidad = vel0.suma(ace.productoEscalarVector(t));<br />}<br />public void calcularDesplazamiento(Vector3D vel0, double t, Vector3D ace){<br />desplazamiento = (vel0.productoEscalarVector(t)).suma((ace.productoEscalarVector(Math.pow(t, 2))).productoEscalarVector(1/2));<br />}<br />public static void main(String args[]){<br />MRUV m = new MRUV();<br />Vector3D r0 = new Vector3D (1,0,-1);<br />Vector3D vel0 = new Vector3D (0,5,0);<br />Vector3D ace = new Vector3D (-4,0,9);<br />double t = 2;<br />System.out.println("POSICION A t = 2s rO = i-k v0 = 5j a = -4i+9k ES: \n" +m.calcularPosicion(r0, vel0, ace, t));<br />System.out.println("VELOCIDAD A t = 2s v0 = 5j a = -4i+9k ES: \n" +m.calcularVelocidad(vel0, t, ace));<br />System.out.println("DESPLAZAMIENTO A t = 2s v0 = 5j a = -4i+9k ES: \n" +m.calcularDesplazamiento(vel0, t, ace));<br />}<br /><br />} <div style='clear: both;'></div> </div> <div class='post-footer'> <div class='post-footer-line post-footer-line-1'> <span class='post-author vcard'> Publicado por <span class='fn' itemprop='author' itemscope='itemscope' itemtype='http://schema.org/Person'> <meta content='https://www.blogger.com/profile/11274018804682176170' itemprop='url'/> <a class='g-profile' href='https://www.blogger.com/profile/11274018804682176170' rel='author' title='author profile'> <span itemprop='name'>jasg587</span> </a> </span> </span> <span class='post-timestamp'> en <meta content='http://jasg587.blogspot.com/2009/11/mruv.html' itemprop='url'/> <a class='timestamp-link' href='https://jasg587.blogspot.com/2009/11/mruv.html' rel='bookmark' title='permanent link'><abbr class='published' itemprop='datePublished' title='2009-11-23T17:11:00-08:00'>17:11</abbr></a> </span> <span class='post-comment-link'> <a class='comment-link' href='https://jasg587.blogspot.com/2009/11/mruv.html#comment-form' onclick=''> No hay comentarios: </a> </span> <span class='post-icons'> <span class='item-action'> <a href='https://www.blogger.com/email-post/524931798993985876/4307639349724912196' title='Enviar entrada por correo electrónico'> <img alt='' class='icon-action' height='13' src='https://resources.blogblog.com/img/icon18_email.gif' width='18'/> </a> </span> <span class='item-control blog-admin pid-844765198'> <a href='https://www.blogger.com/post-edit.g?blogID=524931798993985876&postID=4307639349724912196&from=pencil' title='Editar entrada'> <img alt='' class='icon-action' height='18' src='https://resources.blogblog.com/img/icon18_edit_allbkg.gif' width='18'/> </a> </span> </span> <div class='post-share-buttons goog-inline-block'> </div> </div> <div class='post-footer-line post-footer-line-2'> <span class='post-labels'> </span> </div> <div class='post-footer-line post-footer-line-3'> <span class='post-location'> </span> </div> </div> </div> </div> </div></div> <div class="date-outer"> <h2 class='date-header'><span>domingo, 22 de noviembre de 2009</span></h2> <div class="date-posts"> <div class='post-outer'> <div class='post hentry uncustomized-post-template' itemprop='blogPost' itemscope='itemscope' itemtype='http://schema.org/BlogPosting'> <meta content='524931798993985876' itemprop='blogId'/> <meta content='436923021034288650' itemprop='postId'/> <a name='436923021034288650'></a> <h3 class='post-title entry-title' itemprop='name'> <a href='https://jasg587.blogspot.com/2009/11/mru.html'>MRU</a> </h3> <div class='post-header'> <div class='post-header-line-1'></div> </div> <div class='post-body entry-content' id='post-body-436923021034288650' itemprop='description articleBody'> MRU<br />MATRIZ<br /><br />public class Matriz {<br />public int numeroFilas;<br />public int numeroColumnas;<br />public double [][]matriz;<br /><br /><br />public Matriz(){<br />}<br />public Matriz(int nF, int nC){<br />numeroFilas = nF;<br />numeroColumnas = nC;<br />matriz = new double [numeroFilas][numeroColumnas];<br /><br />for(int i=0; i < numeroFilas; i++)<br />for(int j=0; j < numeroColumnas; j++)<br />matriz[i][j]=0;<br />}<br /><br />public Matriz suma(Matriz b){<br />Matriz resultado;<br />if((this.numeroFilas == b.numeroFilas)&& (this.numeroColumnas == b.numeroColumnas)){<br />resultado = new Matriz(this.numeroFilas, this.numeroColumnas);<br />for(int i=0; i < this.numeroFilas; i++)<br />for(int j=0; j < this.numeroColumnas; j++)<br />resultado.matriz[i][j] = this.matriz[i][j]+ b.matriz[i][j];<br />return resultado;<br />}<br />else<br />System.out.println("DIMENSIONES ERROR");<br />resultado=null;<br />return resultado;<br />}<br /><br />public Matriz multiplicacion(Matriz b){<br />Matriz resultado;<br />if(this.numeroFilas == b.numeroColumnas){<br />resultado=new Matriz(this.numeroFilas,b.numeroColumnas);<br />for(int i=0; i < this.numeroFilas; i++){<br />for(int j=0; j < b.numeroColumnas; j++){<br />for(int k=0; k < this.numeroFilas; k++)<br />resultado.matriz[i][j] += (this.matriz[i][k]*b.matriz[k][j]);<br />}<br />}<br />return resultado;<br />}<br />else<br />System.out.println("DIMENSIONES ERROR ");<br />resultado = null;<br />return resultado;<br />}<br />public String toString(){<br />String aux="\n[\n";<br />for(int i=0; i < numeroFilas; i++){<br />for(int j=0; j < numeroColumnas; j++){<br />aux += matriz[i][j]+" ";<br />}<br />aux+="\n";<br />}<br />aux+= "]";<br />return aux;<br />}<br />}<br /><br />VECTOR3D<br /><br />public class Vector3D extends Matriz {<br />private static Object v;<br />double coorX;<br />double coorY;<br />double coorZ;<br /><br />public Vector3D (){<br />super(1,3);<br />}<br />public Vector3D(double x, double y, double z){<br />super(1,3);<br />this.matriz[0][0] = x;<br />this.matriz[0][1] = y;<br />this.matriz[0][2] = z;<br />coorX = x;<br />coorY = y;<br />coorZ = z;<br />}<br />public double magnitud(){<br />double resultado = 0;<br />//double suma;<br />for(int i = 0; i < 3; i++ ){<br />resultado += this.matriz[0][i]*this.matriz[0][i];<br />}<br />resultado = Math.sqrt(resultado);<br />return resultado;<br />}<br /><br />public double magnitud1(){<br />double resultado;<br />resultado = this.coorX*this.coorX+this.coorY*this.coorY+this.coorZ*this.coorZ;<br />resultado = Math.sqrt(resultado);<br />return resultado;<br />}<br />public Vector3D unitario(){<br />Vector3D unitario = new Vector3D(); <br />for(int i = 0; i < 3; i++)<br />unitario.matriz[0][i] = this.matriz[0][i]/this.magnitud();<br />return unitario;<br />}<br /><br />public double productoEscalar(Vector3D v){<br />double resultado = 0;<br />for(int i = 0; i < 3; i++)<br />resultado += this.matriz[0][i]*v.matriz[0][i];<br /><br />return resultado;<br />}<br />public double magnitud2(){<br />double resultado;<br />resultado = this.coorY*this.coorZ-this.coorY*this.coorZ;<br /><br />return resultado;<br />}<br />public Vector3D productoCruz (Vector3D v){<br />Vector3D productocruz;<br />productocruz = new Vector3D();<br /><br />productocruz.matriz[0][0] = this.matriz[0][1]*v.matriz[0][2]-this.matriz[0][2]*v.matriz[0][1];<br />productocruz.matriz[0][1] = this.matriz[0][0]*v.matriz[0][2]-this.matriz[0][2]*v.matriz[0][0];<br />productocruz.matriz[0][2] = this.matriz[0][0]*v.matriz[0][1]-this.matriz[0][1]*v.matriz[0][0];<br />return productocruz;<br />}<br />public static void main(String args[]){<br />Vector3D v1 = new Vector3D(-1, 1, -1);<br />Vector3D v2 = new Vector3D(0,2,0);<br />System.out.println(v1+"\n"+v2+"\n suma "+(v1.suma(v2)));<br />System.out.println("Coordenada x "+v1.coorX);<br />System.out.println(v1.magnitud()+"\n"+v1.magnitud1());<br />System.out.println(v1.unitario());<br />System.out.println((v1.unitario()).magnitud());<br />System.out.println("Producto escalar "+v1.productoEscalar(v2));<br />System.out.println("Producto cruz "+v1.productoCruz (v2));<br /><br />}<br />}<br />MRU<br /><br />public class MovRecUni {<br />Matriz posicion;<br />Matriz velocidad;<br />Matriz aceleracion;<br /><br />public MovRecUni(){<br />}<br />public MovRecUni(Vector3D pos, Vector3D velo, Vector3D ace){<br />posicion = pos;<br />velocidad = velo;<br />aceleracion = ace;<br />}<br />public void calculaPosición(Vector3D r0, Vector3D vel,double t){<br />posicion = r0.suma(vel.productoVectorEscalar(t));<br /><br />}<br />public void calculaVelocidad(Vector3D vel, double t){<br />velocidad = vel;<br />}<br />public void calculaAceleracion(double t){<br />Vector3D a = new Vector3D();<br />aceleracion = a;<br />}<br />public static void main(String args[]){<br />MovRecUni m = new MovRecUni();<br />Vector3D r0 = new Vector3D(1,0,-1);<br />Vector3D v = new Vector3D(0,5,0); <br />double t = 4;<br /><br />m.calculaPosición(r0, v, t);<br />m.calculaVelocidad(v, t);<br />m.calculaAceleracion(t); <br />System.out.println("Posicion a los 2s para r0 = [i-k] y v0 =[5j] )\n <br />" +m.posicion+"\nvelocidad a t = 2s\n"+m.velocidad+"\n <br />aceleracion\n"+m.aceleracion );<br />}<br />} <div style='clear: both;'></div> </div> <div class='post-footer'> <div class='post-footer-line post-footer-line-1'> <span class='post-author vcard'> Publicado por <span class='fn' itemprop='author' itemscope='itemscope' itemtype='http://schema.org/Person'> <meta content='https://www.blogger.com/profile/11274018804682176170' itemprop='url'/> <a class='g-profile' href='https://www.blogger.com/profile/11274018804682176170' rel='author' title='author profile'> <span itemprop='name'>jasg587</span> </a> </span> </span> <span class='post-timestamp'> en <meta content='http://jasg587.blogspot.com/2009/11/mru.html' itemprop='url'/> <a class='timestamp-link' href='https://jasg587.blogspot.com/2009/11/mru.html' rel='bookmark' title='permanent link'><abbr class='published' itemprop='datePublished' title='2009-11-22T17:25:00-08:00'>17:25</abbr></a> </span> <span class='post-comment-link'> <a class='comment-link' href='https://jasg587.blogspot.com/2009/11/mru.html#comment-form' onclick=''> No hay comentarios: </a> </span> <span class='post-icons'> <span class='item-action'> <a href='https://www.blogger.com/email-post/524931798993985876/436923021034288650' title='Enviar entrada por correo electrónico'> <img alt='' class='icon-action' height='13' src='https://resources.blogblog.com/img/icon18_email.gif' width='18'/> </a> </span> <span class='item-control blog-admin pid-844765198'> <a href='https://www.blogger.com/post-edit.g?blogID=524931798993985876&postID=436923021034288650&from=pencil' title='Editar entrada'> <img alt='' class='icon-action' height='18' src='https://resources.blogblog.com/img/icon18_edit_allbkg.gif' width='18'/> </a> </span> </span> <div class='post-share-buttons goog-inline-block'> </div> </div> <div class='post-footer-line post-footer-line-2'> <span class='post-labels'> </span> </div> <div class='post-footer-line post-footer-line-3'> <span class='post-location'> </span> </div> </div> </div> </div> </div></div> </div> <div class='blog-pager' id='blog-pager'> <span id='blog-pager-older-link'> <a class='blog-pager-older-link' href='https://jasg587.blogspot.com/search?updated-max=2009-11-22T17:25:00-08:00&max-results=7' id='Blog1_blog-pager-older-link' title='Entradas antiguas'>Entradas antiguas</a> </span> <a class='home-link' href='https://jasg587.blogspot.com/'>Inicio</a> </div> <div class='clear'></div> <div class='blog-feeds'> <div class='feed-links'> Suscribirse a: <a class='feed-link' href='https://jasg587.blogspot.com/feeds/posts/default' target='_blank' type='application/atom+xml'>Comentarios (Atom)</a> </div> </div> </div></div> </div> <div id='sidebar-wrapper'> <div class='sidebar section' id='sidebar'><div class='widget Followers' data-version='1' id='Followers1'> <h2 class='title'>Seguidores</h2> <div class='widget-content'> <div id='Followers1-wrapper'> <div style='margin-right:2px;'> <div><script type="text/javascript" src="https://apis.google.com/js/platform.js"></script> <div id="followers-iframe-container"></div> <script type="text/javascript"> window.followersIframe = null; function followersIframeOpen(url) { gapi.load("gapi.iframes", function() { if (gapi.iframes && gapi.iframes.getContext) { window.followersIframe = gapi.iframes.getContext().openChild({ url: url, where: document.getElementById("followers-iframe-container"), messageHandlersFilter: gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER, messageHandlers: { '_ready': function(obj) { window.followersIframe.getIframeEl().height = obj.height; }, 'reset': function() { window.followersIframe.close(); followersIframeOpen("https://www.blogger.com/followers/frame/524931798993985876?colors\x3dCgt0cmFuc3BhcmVudBILdHJhbnNwYXJlbnQaByM2NjY2NjYiByM1NTg4YWEqByNmZmZmZmYyByNjYzY2MDA6ByM2NjY2NjZCByM1NTg4YWFKByM5OTk5OTlSByM1NTg4YWFaC3RyYW5zcGFyZW50\x26pageSize\x3d21\x26hl\x3des\x26origin\x3dhttps://jasg587.blogspot.com"); }, 'open': function(url) { window.followersIframe.close(); followersIframeOpen(url); } } }); } }); } followersIframeOpen("https://www.blogger.com/followers/frame/524931798993985876?colors\x3dCgt0cmFuc3BhcmVudBILdHJhbnNwYXJlbnQaByM2NjY2NjYiByM1NTg4YWEqByNmZmZmZmYyByNjYzY2MDA6ByM2NjY2NjZCByM1NTg4YWFKByM5OTk5OTlSByM1NTg4YWFaC3RyYW5zcGFyZW50\x26pageSize\x3d21\x26hl\x3des\x26origin\x3dhttps://jasg587.blogspot.com"); </script></div> </div> </div> <div class='clear'></div> </div> </div><div class='widget Profile' data-version='1' id='Profile1'> <h2>Colaboradores</h2> <div class='widget-content'> <ul> <li><a class='profile-name-link g-profile' href='https://www.blogger.com/profile/01811426162978848151' style='background-image: url(//www.blogger.com/img/logo-16.png);'>Andres Narvaez</a></li> <li><a class='profile-name-link g-profile' href='https://www.blogger.com/profile/14669274896199099169' style='background-image: url(//www.blogger.com/img/logo-16.png);'>Diego Tonello</a></li> <li><a class='profile-name-link g-profile' href='https://www.blogger.com/profile/04727004964737030015' style='background-image: url(//www.blogger.com/img/logo-16.png);'>PROGRAMACION 2</a></li> <li><a class='profile-name-link g-profile' href='https://www.blogger.com/profile/11274018804682176170' style='background-image: url(//www.blogger.com/img/logo-16.png);'>jasg587</a></li> </ul> <div class='clear'></div> </div> </div></div> </div> <!-- spacer for skins that want sidebar and main to be the same height--> <div class='clear'> </div> </div> <!-- end content-wrapper --> <div id='footer-wrapper'> <div class='footer section' id='footer'><div class='widget BlogArchive' data-version='1' id='BlogArchive1'> <h2>Archivo del blog</h2> <div class='widget-content'> <div id='ArchiveList'> <div id='BlogArchive1_ArchiveList'> <ul class='hierarchy'> <li class='archivedate expanded'> <a class='toggle' href='javascript:void(0)'> <span class='zippy toggle-open'> ▼  </span> </a> <a class='post-count-link' href='https://jasg587.blogspot.com/2010/'> 2010 </a> <span class='post-count' dir='ltr'>(1)</span> <ul class='hierarchy'> <li class='archivedate expanded'> <a class='toggle' href='javascript:void(0)'> <span class='zippy toggle-open'> ▼  </span> </a> <a class='post-count-link' href='https://jasg587.blogspot.com/2010/01/'> enero </a> <span class='post-count' dir='ltr'>(1)</span> <ul class='posts'> <li><a href='https://jasg587.blogspot.com/2010/01/sensor-temperatura.html'>sensor temperatura</a></li> </ul> </li> </ul> </li> </ul> <ul class='hierarchy'> <li class='archivedate collapsed'> <a class='toggle' href='javascript:void(0)'> <span class='zippy'> ►  </span> </a> <a class='post-count-link' href='https://jasg587.blogspot.com/2009/'> 2009 </a> <span class='post-count' dir='ltr'>(17)</span> <ul class='hierarchy'> <li class='archivedate collapsed'> <a class='toggle' href='javascript:void(0)'> <span class='zippy'> ►  </span> </a> <a class='post-count-link' href='https://jasg587.blogspot.com/2009/12/'> diciembre </a> <span class='post-count' dir='ltr'>(3)</span> </li> </ul> <ul class='hierarchy'> <li class='archivedate collapsed'> <a class='toggle' href='javascript:void(0)'> <span class='zippy'> ►  </span> </a> <a class='post-count-link' href='https://jasg587.blogspot.com/2009/11/'> noviembre </a> <span class='post-count' dir='ltr'>(3)</span> </li> </ul> <ul class='hierarchy'> <li class='archivedate collapsed'> <a class='toggle' href='javascript:void(0)'> <span class='zippy'> ►  </span> </a> <a class='post-count-link' href='https://jasg587.blogspot.com/2009/10/'> octubre </a> <span class='post-count' dir='ltr'>(5)</span> </li> </ul> <ul class='hierarchy'> <li class='archivedate collapsed'> <a class='toggle' href='javascript:void(0)'> <span class='zippy'> ►  </span> </a> <a class='post-count-link' href='https://jasg587.blogspot.com/2009/09/'> septiembre </a> <span class='post-count' dir='ltr'>(6)</span> </li> </ul> </li> </ul> </div> </div> <div class='clear'></div> </div> </div></div> </div> </div></div> <!-- end outer-wrapper --> <script type="text/javascript" src="https://www.blogger.com/static/v1/widgets/344097953-widgets.js"></script> <script type='text/javascript'> window['__wavt'] = 'APlU3lwPgrWLoxZGq0U_T0F1fC8I:1775395070048';_WidgetManager._Init('//www.blogger.com/rearrange?blogID\x3d524931798993985876','//jasg587.blogspot.com/','524931798993985876'); _WidgetManager._SetDataContext([{'name': 'blog', 'data': {'blogId': '524931798993985876', 'title': 'Mecatr\xf3nica', 'url': 'https://jasg587.blogspot.com/', 'canonicalUrl': 'http://jasg587.blogspot.com/', 'homepageUrl': 'https://jasg587.blogspot.com/', 'searchUrl': 'https://jasg587.blogspot.com/search', 'canonicalHomepageUrl': 'http://jasg587.blogspot.com/', 'blogspotFaviconUrl': 'https://jasg587.blogspot.com/favicon.ico', 'bloggerUrl': 'https://www.blogger.com', 'hasCustomDomain': false, 'httpsEnabled': true, 'enabledCommentProfileImages': true, 'gPlusViewType': 'FILTERED_POSTMOD', 'adultContent': false, 'analyticsAccountNumber': '', 'encoding': 'UTF-8', 'locale': 'es', 'localeUnderscoreDelimited': 'es', 'languageDirection': 'ltr', 'isPrivate': false, 'isMobile': false, 'isMobileRequest': false, 'mobileClass': '', 'isPrivateBlog': false, 'isDynamicViewsAvailable': true, 'feedLinks': '\x3clink rel\x3d\x22alternate\x22 type\x3d\x22application/atom+xml\x22 title\x3d\x22Mecatr\xf3nica - Atom\x22 href\x3d\x22https://jasg587.blogspot.com/feeds/posts/default\x22 /\x3e\n\x3clink rel\x3d\x22alternate\x22 type\x3d\x22application/rss+xml\x22 title\x3d\x22Mecatr\xf3nica - RSS\x22 href\x3d\x22https://jasg587.blogspot.com/feeds/posts/default?alt\x3drss\x22 /\x3e\n\x3clink rel\x3d\x22service.post\x22 type\x3d\x22application/atom+xml\x22 title\x3d\x22Mecatr\xf3nica - Atom\x22 href\x3d\x22https://www.blogger.com/feeds/524931798993985876/posts/default\x22 /\x3e\n', 'meTag': '\x3clink rel\x3d\x22me\x22 href\x3d\x22https://www.blogger.com/profile/11274018804682176170\x22 /\x3e\n', 'adsenseHostId': 'ca-host-pub-1556223355139109', 'adsenseHasAds': false, 'adsenseAutoAds': false, 'boqCommentIframeForm': true, 'loginRedirectParam': '', 'isGoogleEverywhereLinkTooltipEnabled': true, 'view': '', 'dynamicViewsCommentsSrc': '//www.blogblog.com/dynamicviews/4224c15c4e7c9321/js/comments.js', 'dynamicViewsScriptSrc': '//www.blogblog.com/dynamicviews/16d2a080d6cf52d7', 'plusOneApiSrc': 'https://apis.google.com/js/platform.js', 'disableGComments': true, 'interstitialAccepted': false, 'sharing': {'platforms': [{'name': 'Obtener enlace', 'key': 'link', 'shareMessage': 'Obtener enlace', 'target': ''}, {'name': 'Facebook', 'key': 'facebook', 'shareMessage': 'Compartir en Facebook', 'target': 'facebook'}, {'name': 'Escribe un blog', 'key': 'blogThis', 'shareMessage': 'Escribe un blog', 'target': 'blog'}, {'name': 'X', 'key': 'twitter', 'shareMessage': 'Compartir en X', 'target': 'twitter'}, {'name': 'Pinterest', 'key': 'pinterest', 'shareMessage': 'Compartir en Pinterest', 'target': 'pinterest'}, {'name': 'Correo electr\xf3nico', 'key': 'email', 'shareMessage': 'Correo electr\xf3nico', 'target': 'email'}], 'disableGooglePlus': true, 'googlePlusShareButtonWidth': 0, 'googlePlusBootstrap': '\x3cscript type\x3d\x22text/javascript\x22\x3ewindow.___gcfg \x3d {\x27lang\x27: \x27es\x27};\x3c/script\x3e'}, 'hasCustomJumpLinkMessage': false, 'jumpLinkMessage': 'Leer m\xe1s', 'pageType': 'index', 'pageName': '', 'pageTitle': 'Mecatr\xf3nica'}}, {'name': 'features', 'data': {}}, {'name': 'messages', 'data': {'edit': 'Editar', 'linkCopiedToClipboard': 'El enlace se ha copiado en el Portapapeles.', 'ok': 'Aceptar', 'postLink': 'Enlace de la entrada'}}, {'name': 'template', 'data': {'isResponsive': false, 'isAlternateRendering': false, 'isCustom': false}}, {'name': 'view', 'data': {'classic': {'name': 'classic', 'url': '?view\x3dclassic'}, 'flipcard': {'name': 'flipcard', 'url': '?view\x3dflipcard'}, 'magazine': {'name': 'magazine', 'url': '?view\x3dmagazine'}, 'mosaic': {'name': 'mosaic', 'url': '?view\x3dmosaic'}, 'sidebar': {'name': 'sidebar', 'url': '?view\x3dsidebar'}, 'snapshot': {'name': 'snapshot', 'url': '?view\x3dsnapshot'}, 'timeslide': {'name': 'timeslide', 'url': '?view\x3dtimeslide'}, 'isMobile': false, 'title': 'Mecatr\xf3nica', 'description': '', 'url': 'https://jasg587.blogspot.com/', 'type': 'feed', 'isSingleItem': false, 'isMultipleItems': true, 'isError': false, 'isPage': false, 'isPost': false, 'isHomepage': true, 'isArchive': false, 'isLabelSearch': false}}]); _WidgetManager._RegisterWidget('_NavbarView', new _WidgetInfo('Navbar1', 'navbar', document.getElementById('Navbar1'), {}, 'displayModeFull')); _WidgetManager._RegisterWidget('_HeaderView', new _WidgetInfo('Header1', 'header', document.getElementById('Header1'), {}, 'displayModeFull')); _WidgetManager._RegisterWidget('_BlogView', new _WidgetInfo('Blog1', 'main', document.getElementById('Blog1'), {'cmtInteractionsEnabled': false, 'lightboxEnabled': true, 'lightboxModuleUrl': 'https://www.blogger.com/static/v1/jsbin/3672787217-lbx__es.js', 'lightboxCssUrl': 'https://www.blogger.com/static/v1/v-css/828616780-lightbox_bundle.css'}, 'displayModeFull')); _WidgetManager._RegisterWidget('_FollowersView', new _WidgetInfo('Followers1', 'sidebar', document.getElementById('Followers1'), {}, 'displayModeFull')); _WidgetManager._RegisterWidget('_ProfileView', new _WidgetInfo('Profile1', 'sidebar', document.getElementById('Profile1'), {}, 'displayModeFull')); _WidgetManager._RegisterWidget('_BlogArchiveView', new _WidgetInfo('BlogArchive1', 'footer', document.getElementById('BlogArchive1'), {'languageDirection': 'ltr', 'loadingMessage': 'Cargando\x26hellip;'}, 'displayModeFull')); </script> </body> </html>