import javax.swing.*;
public class Sensor {
private int vel;
public Sensor(){
}
public void setVel(int v) {
vel = v;
}
public int getVel(){
return vel;
}
public void leerVel(){
String aux;
aux = JOptionPane.showInputDialog("Ingrese la velocidad en Km/h");
vel = Integer.parseInt(aux);
}
public static void main(String args[]){
Sensor s = new Sensor();
s.leerVel();
System.out.println("Velocidad = "+s.getVel());
}
}
import javax.swing.*;
import java.awt.*;
public class Interfase2 extends JFrame{
public Interfase2(){
super("VELOCIMETRO");
setSize(600,400);
show();
}
public void paint(Graphics g){
super.paint(g);
g.setColor(Color.BLUE);
g.drawRect(50, 100, 20, 280);
g.setColor(Color.BLACK);
g.drawString("280 Km/h", 75, 100);
g.drawString("0 Km/h", 75, 380);
g.drawString("Alerta", 140, 90);
g.drawOval(150, 100, 20, 20);
g.setColor(Color.BLACK);
g.drawOval(400, 150, 150, 150);
g.setColor(Color.BLACK);
g.drawString("!!!Alerta!!!", 470, 90);
g.drawOval(470, 100, 20, 20);
g.setColor(Color.gray);
g.fillOval(400, 150, 150, 150);
g.setColor(Color.BLACK);{
g.drawLine(300, 0, 300, 1000);
g.drawString("Sensor de Velocidad Lineal",60 , 50);
g.drawString("Sensor de Velocidad", 400, 50);
g.drawString("PASTEL DE PORCENTAJE", 400,70);
}
Sensor s = new Sensor();
s.leerVel();
if(s.getVel()>0& s.getVel()<80){
g.setColor(Color.YELLOW);
g.fillArc(400, 150, 150, 150, 210, ((((s.getVel()*100)/280)*360))/100);
g.setColor(Color.WHITE);
g.drawString(((s.getVel()*100)/280)+"% de la Vel Max", 430, 220);
g.setColor(Color.GREEN);
g.fillOval(470, 100, 20, 20);
}
if(s.getVel()>=80& s.getVel()<150){
g.setColor(Color.ORANGE);
g.fillArc(400, 150, 150, 150, 210, ((((s.getVel()*100)/280)*360))/100);
g.setColor(Color.WHITE);
g.drawString(((s.getVel()*100)/280)+"% de la Vel Max", 430, 220);
g.setColor(Color.GREEN);
g.fillOval(470, 100, 20, 20);
}
if(s.getVel()>=150& s.getVel()<=280){
g.setColor(Color.RED);
g.fillArc(400, 150, 150, 150, 210, ((((s.getVel()*100)/280)*360))/100);
g.setColor(Color.WHITE);
g.drawString(((s.getVel()*100)/280)+"% de la Vel Max", 430, 220);
g.setColor(Color.RED);
g.fillOval(470, 100, 20, 20);
}
if (s.getVel()>0& s.getVel()<100){
g.setColor(Color.BLUE);
g.fillRect(50, 380-s.getVel(), 20, s.getVel());
g.drawString(s.getVel()+" Km/h", 75, 380-s.getVel());
g.setColor(Color.GREEN);
g.fillOval(150, 100, 20, 20);
}
if(s.getVel()>=100& s.getVel()<180){
g.setColor(Color.YELLOW);
g.fillRect(50, 380-s.getVel(), 20, s.getVel());
g.drawString(s.getVel()+" Km/h", 75, 380-s.getVel());
g.setColor(Color.GREEN);
g.fillOval(150, 100, 20, 20);
}
if(s.getVel()>=180& s.getVel()<=280){
g.setColor(Color.RED);
g.fillRect(50, 380-s.getVel(), 20, s.getVel());
g.drawString(s.getVel()+" Km/h", 75, 380-s.getVel());
g.setColor(Color.RED);
g.fillOval(150, 100, 20, 20);
}
}
public static void main(String args[]){
Interfase2 vel = new Interfase2();
vel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
martes, 12 de enero de 2010
TRABAJO-PREGUNTA3
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];
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;
}
public Matriz resta(Matriz b){
Matriz resultado;
if ((this.numeroFilas == b.numeroFilas)&(this.numeroFilas == 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;
}
}
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 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 resultado = new Matriz (this.numeroFilas, this.numeroColumnas);
for(int i=0; i
for(int j=0; j
resultado.matriz[0][0]=((this.matriz[1][1]*this.matriz[2][2])-(this.matriz[2][1]*this.matriz[1][2]));
resultado.matriz[0][1]=((this.matriz[1][0]*this.matriz[2][2])-(this.matriz[2][0]*this.matriz[1][2]));
resultado.matriz[0][2]=((this.matriz[1][0]*this.matriz[2][1])-(this.matriz[2][0]*this.matriz[1][1]));
resultado.matriz[1][0]=((this.matriz[0][1]*this.matriz[2][2])-(this.matriz[2][1]*this.matriz[0][2]));
resultado.matriz[1][1]=((this.matriz[1][0]*this.matriz[2][2])-(this.matriz[2][0]*this.matriz[1][2]));
resultado.matriz[1][2]=((this.matriz[0][0]*this.matriz[2][1])-(this.matriz[2][0]*this.matriz[0][1]));
resultado.matriz[2][0]=((this.matriz[0][1]*this.matriz[1][2])-(this.matriz[1][1]*this.matriz[0][2]));
resultado.matriz[2][1]=((this.matriz[0][0]*this.matriz[1][2])-(this.matriz[1][0]*this.matriz[0][2]));
resultado.matriz[2][2]=((this.matriz[0][0]*this.matriz[1][1])-(this.matriz[1][0]*this.matriz[0][1]));
return resultado;
}
public double deteminantes(){
double suma=0;
for(int i=0; i
for(int j=0; j
suma = this.matriz[i][j+1]-this.matriz[i+1][j];
return suma;
}
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[\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;
}
public static void main(String args[]){
Matriz a= new Matriz(3,3);
a.matriz[0][0]=1; a.matriz[0][1]=2;
a.matriz[1][0]=3; a.matriz[1][1]=7;
a.matriz[2][0]=3; a.matriz[2][2]=7;
System.out.println("la inversa es " +(a.deteminantes()));
}
}
public class Operaciones extends javax.swing.JApplet {
/** Initializes the applet Operaciones */
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() {
jTextField1 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jTextField2 = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jTextField3 = new javax.swing.JTextField();
jTextField4 = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
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();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jTextField5 = new javax.swing.JTextField();
jTextField6 = new javax.swing.JTextField();
jScrollPane2 = new javax.swing.JScrollPane();
jTextArea2 = new javax.swing.JTextArea();
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
jLabel2.setText("MATRIZ UNO");
jLabel2.setAlignmentY(-1.0F);
jLabel3.setText("numero de filas");
jLabel4.setText("numero de columnas");
jLabel5.setText("MATRIZ DOS");
jLabel6.setText("numero de filas");
jLabel7.setText("numero de columnas");
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
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);
}
});
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);
}
});
jButton6.setText("determinantes");
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton6ActionPerformed(evt);
}
});
jLabel9.setText("numero de columnas");
jLabel10.setText("numero de filas");
jTextArea2.setColumns(20);
jTextArea2.setRows(5);
jScrollPane2.setViewportView(jTextArea2);
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)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel2)
.addComponent(jLabel3))
.addGap(29, 29, 29)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jTextField2)
.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel4)
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField4, javax.swing.GroupLayout.DEFAULT_SIZE, 58, Short.MAX_VALUE)
.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 58, Short.MAX_VALUE))))
.addComponent(jButton4)
.addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(37, 37, 37))
.addGroup(layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel10)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel9)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(37, 37, 37)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton3)
.addGap(22, 22, 22)
.addComponent(jButton2))
.addGroup(layout.createSequentialGroup()
.addGap(34, 34, 34)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jButton5)
.addGap(31, 31, 31)
.addComponent(jButton6))
.addGroup(layout.createSequentialGroup()
.addGap(11, 11, 11)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 316, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(851, 851, 851))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton3)
.addComponent(jButton2))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(13, 13, 13)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.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.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton4)
.addComponent(jButton5)
.addComponent(jButton6))
.addGap(30, 30, 30)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())))
);
}//
private void jTextField1ActionPerformed(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) {
// 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("Resta de Matrices: \n"+aux1+(m1.resta(m2)).toString());
}
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.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) {
// TODO add your handling code here:
String aux = jTextField5.getText();
String aux1="";
int nF = Integer.parseInt(aux);
aux = jTextField6.getText();
int nC = Integer.parseInt(aux);
m1 = new Matriz(nF,nC);
m1.leer();
aux1 += m1.toString();
jTextArea2.setText("La transpuesta de la matriz es: \n"+aux1+(m1.Transpuesta()).toString());
}
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String aux = jTextField5.getText();
String aux1="";
int nF = Integer.parseInt(aux);
aux = jTextField6.getText();
int nC = Integer.parseInt(aux);
m1 = new Matriz(nF,nC);
m1.leer();
aux1 += m1.toString();
jTextArea2.setText("La inversa de la matriz es: \n"+aux1+(m1.inversa()).toString());
}
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
// 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.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JLabel jLabel10;
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 jLabel9;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
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;
// End of variables declaration
}
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];
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;
}
public Matriz resta(Matriz b){
Matriz resultado;
if ((this.numeroFilas == b.numeroFilas)&(this.numeroFilas == 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;
}
}
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 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 resultado = new Matriz (this.numeroFilas, this.numeroColumnas);
for(int i=0; i
for(int j=0; j
resultado.matriz[0][0]=((this.matriz[1][1]*this.matriz[2][2])-(this.matriz[2][1]*this.matriz[1][2]));
resultado.matriz[0][1]=((this.matriz[1][0]*this.matriz[2][2])-(this.matriz[2][0]*this.matriz[1][2]));
resultado.matriz[0][2]=((this.matriz[1][0]*this.matriz[2][1])-(this.matriz[2][0]*this.matriz[1][1]));
resultado.matriz[1][0]=((this.matriz[0][1]*this.matriz[2][2])-(this.matriz[2][1]*this.matriz[0][2]));
resultado.matriz[1][1]=((this.matriz[1][0]*this.matriz[2][2])-(this.matriz[2][0]*this.matriz[1][2]));
resultado.matriz[1][2]=((this.matriz[0][0]*this.matriz[2][1])-(this.matriz[2][0]*this.matriz[0][1]));
resultado.matriz[2][0]=((this.matriz[0][1]*this.matriz[1][2])-(this.matriz[1][1]*this.matriz[0][2]));
resultado.matriz[2][1]=((this.matriz[0][0]*this.matriz[1][2])-(this.matriz[1][0]*this.matriz[0][2]));
resultado.matriz[2][2]=((this.matriz[0][0]*this.matriz[1][1])-(this.matriz[1][0]*this.matriz[0][1]));
return resultado;
}
public double deteminantes(){
double suma=0;
for(int i=0; i
for(int j=0; j
suma = this.matriz[i][j+1]-this.matriz[i+1][j];
return suma;
}
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[\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;
}
public static void main(String args[]){
Matriz a= new Matriz(3,3);
a.matriz[0][0]=1; a.matriz[0][1]=2;
a.matriz[1][0]=3; a.matriz[1][1]=7;
a.matriz[2][0]=3; a.matriz[2][2]=7;
System.out.println("la inversa es " +(a.deteminantes()));
}
}
public class Operaciones extends javax.swing.JApplet {
/** Initializes the applet Operaciones */
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() {
jTextField1 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jTextField2 = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jTextField3 = new javax.swing.JTextField();
jTextField4 = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
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();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jTextField5 = new javax.swing.JTextField();
jTextField6 = new javax.swing.JTextField();
jScrollPane2 = new javax.swing.JScrollPane();
jTextArea2 = new javax.swing.JTextArea();
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
jLabel2.setText("MATRIZ UNO");
jLabel2.setAlignmentY(-1.0F);
jLabel3.setText("numero de filas");
jLabel4.setText("numero de columnas");
jLabel5.setText("MATRIZ DOS");
jLabel6.setText("numero de filas");
jLabel7.setText("numero de columnas");
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
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);
}
});
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);
}
});
jButton6.setText("determinantes");
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton6ActionPerformed(evt);
}
});
jLabel9.setText("numero de columnas");
jLabel10.setText("numero de filas");
jTextArea2.setColumns(20);
jTextArea2.setRows(5);
jScrollPane2.setViewportView(jTextArea2);
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)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel2)
.addComponent(jLabel3))
.addGap(29, 29, 29)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jTextField2)
.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel4)
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField4, javax.swing.GroupLayout.DEFAULT_SIZE, 58, Short.MAX_VALUE)
.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 58, Short.MAX_VALUE))))
.addComponent(jButton4)
.addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(37, 37, 37))
.addGroup(layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel10)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel9)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(37, 37, 37)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton3)
.addGap(22, 22, 22)
.addComponent(jButton2))
.addGroup(layout.createSequentialGroup()
.addGap(34, 34, 34)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jButton5)
.addGap(31, 31, 31)
.addComponent(jButton6))
.addGroup(layout.createSequentialGroup()
.addGap(11, 11, 11)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 316, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(851, 851, 851))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton3)
.addComponent(jButton2))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(13, 13, 13)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.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.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton4)
.addComponent(jButton5)
.addComponent(jButton6))
.addGap(30, 30, 30)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())))
);
}//
private void jTextField1ActionPerformed(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) {
// 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("Resta de Matrices: \n"+aux1+(m1.resta(m2)).toString());
}
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.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) {
// TODO add your handling code here:
String aux = jTextField5.getText();
String aux1="";
int nF = Integer.parseInt(aux);
aux = jTextField6.getText();
int nC = Integer.parseInt(aux);
m1 = new Matriz(nF,nC);
m1.leer();
aux1 += m1.toString();
jTextArea2.setText("La transpuesta de la matriz es: \n"+aux1+(m1.Transpuesta()).toString());
}
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String aux = jTextField5.getText();
String aux1="";
int nF = Integer.parseInt(aux);
aux = jTextField6.getText();
int nC = Integer.parseInt(aux);
m1 = new Matriz(nF,nC);
m1.leer();
aux1 += m1.toString();
jTextArea2.setText("La inversa de la matriz es: \n"+aux1+(m1.inversa()).toString());
}
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
// 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.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JLabel jLabel10;
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 jLabel9;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
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;
// End of variables declaration
}
TRABAJO- PREGUNTA2
¿Qué es un Applet?
• Definición: Podemos decir que un applet es un componente de unaaplicación que se ejecuta en el contexto de otro programa, por ejemplo un navegador web. El applet debe ejecutarse en un contenedor, que lo proporciona un programa anfitrión, mediante un plugin, o en aplicaciones como teléfonos móviles que soportan el modelo de programación porapplets.
Un applet no puede ejecutarse de manera independiente. Un appletnormalmente lleva a cabo una función muy específica que carece de uso independiente.
• Funcionamiento
Un Java applet es un código JAVA que carece de un método main, por eso se utiliza principalmente para el trabajo de páginas web, ya que es un pequeño programa que es utilizado en una página HTML y representado por una pequeña pantalla gráfica dentro de ésta.
Un applet Java es un applet escrito en el lenguaje de programación Java. Los applets de Java pueden correr en un navegador web utilizando la Java Virtual Machine (JVM), o en el AppletViewer de Sun.
Java puede funcionar como una aplicación sola o como un "applet", que es un pequeño programa hecho en Java. Los applets de Java se pueden "pegar" a una página de Web (HTML), y con esto puedes tener un programa que cualquier persona que tenga un browser compatible podrá usar.
Java funciona de la siguiente manera: El compilador de Java deja el programa en un Pseudo-código (no es código maquinal) y luego el intérprete de Java ejecuta el programa (lo que se conoce como el "Java Virtual Machine"). Por eso Java es multiplataforma, existe un intérprete para cada máquina diferente.
Para entender bien como funciona un applet de Java vean el siguiente ejemplo:
1. Existe un código de Java en un servidor de Web. (Los códigos de Java se caracterizan por tener la extensión *.class).
2. Si el usuario realiza otra conexión a otro URL o se sale del browser, el programa se deja de ejecutar y en la computadora no queda rastro de el.Una persona en Internet, con un browser compatible con Java, realiza una conección al servidor.
3. El servidor envía el documento HTML y el código en Java (*.class).
4. En la computadora del usuario remoto llegan ambos, y la Máquina Virtual de Java, que está en el browser, transforma el código Java en un código que entienda la máquina local y se ejecuta el programa dentro de la página de Web.
5. Una persona en Internet, con un browser compatible con Java, realiza una conección al servidor.
• Definición: Podemos decir que un applet es un componente de unaaplicación que se ejecuta en el contexto de otro programa, por ejemplo un navegador web. El applet debe ejecutarse en un contenedor, que lo proporciona un programa anfitrión, mediante un plugin, o en aplicaciones como teléfonos móviles que soportan el modelo de programación porapplets.
Un applet no puede ejecutarse de manera independiente. Un appletnormalmente lleva a cabo una función muy específica que carece de uso independiente.
• Funcionamiento
Un Java applet es un código JAVA que carece de un método main, por eso se utiliza principalmente para el trabajo de páginas web, ya que es un pequeño programa que es utilizado en una página HTML y representado por una pequeña pantalla gráfica dentro de ésta.
Un applet Java es un applet escrito en el lenguaje de programación Java. Los applets de Java pueden correr en un navegador web utilizando la Java Virtual Machine (JVM), o en el AppletViewer de Sun.
Java puede funcionar como una aplicación sola o como un "applet", que es un pequeño programa hecho en Java. Los applets de Java se pueden "pegar" a una página de Web (HTML), y con esto puedes tener un programa que cualquier persona que tenga un browser compatible podrá usar.
Java funciona de la siguiente manera: El compilador de Java deja el programa en un Pseudo-código (no es código maquinal) y luego el intérprete de Java ejecuta el programa (lo que se conoce como el "Java Virtual Machine"). Por eso Java es multiplataforma, existe un intérprete para cada máquina diferente.
Para entender bien como funciona un applet de Java vean el siguiente ejemplo:
1. Existe un código de Java en un servidor de Web. (Los códigos de Java se caracterizan por tener la extensión *.class).
2. Si el usuario realiza otra conexión a otro URL o se sale del browser, el programa se deja de ejecutar y en la computadora no queda rastro de el.Una persona en Internet, con un browser compatible con Java, realiza una conección al servidor.
3. El servidor envía el documento HTML y el código en Java (*.class).
4. En la computadora del usuario remoto llegan ambos, y la Máquina Virtual de Java, que está en el browser, transforma el código Java en un código que entienda la máquina local y se ejecuta el programa dentro de la página de Web.
5. Una persona en Internet, con un browser compatible con Java, realiza una conección al servidor.
TRABAJO- PREGUNTA1
Librería AWT
Se trata de una biblioteca de clases Java para el desarrollo de Interfaces de usuario Gráficas las cuales permiten generar componentes gráficos y gestionar eventos.Su aspecto visual depende de la plataforma.
Caracteristicas:
1. Genera interfaces gráficas, independiente de la plataforma en que se ejecute la aplicación.
2. Los Contenedores contienen a los controles básicos
3. Depende de la máquina en que se ejecuta la aplicación
4. No tiene formato de recursos sin poder separar el código de la interface.
5. No se usan posiciones fijas están situados a través de una disposición controlada (layouts)
6. Alto nivel de abstracción al entorno de ventanas en que se ejecute la aplicación
7. La arquitectura de la aplicación depende del entorno de ventanas, no tiene un tamaño fijo
Estructura
Container: Contenedor.
Label: Etiqueta de texto
Button: Botón de comando
Canvas: Area de dibujo.
Choice: Lista de selección.
List: Lista de datos.
Scrollbar: Barra de desplazamiento.
TextComponent: Componente de texto.
Container: Contienen en su interior al resto de componentes
Button: Botón de comando
Canvas: área de dibujo.
Checkbox: Caja de comprobación.
CheckboxGroup: Grupo de cajas de chequeo.
Librería Swing
Proporciona componentes de presentación visual independiente a la plataforma en la que se ejecuta. Swing extiende AWT y añade nuevas características, mejoras y componentes para interactuar con el usuario, tales como árboles, pestañas, tablas, etc.
Existen muchas versiones de swing en el mercado
Caracteristicas
1.Cambia la gestión del texto creando texto de colores con distintos tipos de caracteres.
2. Se puede introducir imágenes y decodificar los archivos de html, rtf.
3. Gestionar sucesos con el paquete de java.awt.event.
Se trata de una biblioteca de clases Java para el desarrollo de Interfaces de usuario Gráficas las cuales permiten generar componentes gráficos y gestionar eventos.Su aspecto visual depende de la plataforma.
Caracteristicas:
1. Genera interfaces gráficas, independiente de la plataforma en que se ejecute la aplicación.
2. Los Contenedores contienen a los controles básicos
3. Depende de la máquina en que se ejecuta la aplicación
4. No tiene formato de recursos sin poder separar el código de la interface.
5. No se usan posiciones fijas están situados a través de una disposición controlada (layouts)
6. Alto nivel de abstracción al entorno de ventanas en que se ejecute la aplicación
7. La arquitectura de la aplicación depende del entorno de ventanas, no tiene un tamaño fijo
Estructura
Container: Contenedor.
Label: Etiqueta de texto
Button: Botón de comando
Canvas: Area de dibujo.
Choice: Lista de selección.
List: Lista de datos.
Scrollbar: Barra de desplazamiento.
TextComponent: Componente de texto.
Container: Contienen en su interior al resto de componentes
Button: Botón de comando
Canvas: área de dibujo.
Checkbox: Caja de comprobación.
CheckboxGroup: Grupo de cajas de chequeo.
Librería Swing
Proporciona componentes de presentación visual independiente a la plataforma en la que se ejecuta. Swing extiende AWT y añade nuevas características, mejoras y componentes para interactuar con el usuario, tales como árboles, pestañas, tablas, etc.
Existen muchas versiones de swing en el mercado
Caracteristicas
1.Cambia la gestión del texto creando texto de colores con distintos tipos de caracteres.
2. Se puede introducir imágenes y decodificar los archivos de html, rtf.
3. Gestionar sucesos con el paquete de java.awt.event.
SENSOR VELOCIDAD
import javax.swing.*;
public class Sensor {
private int vel;
public Sensor(){
}
public void setVel(int v) {
vel = v;
}
public int getVel(){
return vel;
}
public void leerVel(){
String aux;
aux = JOptionPane.showInputDialog("Ingrese la velocidad en Km/h");
vel = Integer.parseInt(aux);
}
public static void main(String args[]){
Sensor s = new Sensor();
s.leerVel();
System.out.println("Velocidad = "+s.getVel());
}
}
import javax.swing.*;
import java.awt.*;
public class Interfase2 extends JFrame{
public Interfase2(){
super("VELOCIMETRO");
setSize(400,400);
show();
}
public void paint(Graphics g){
super.paint(g);
g.setColor(Color.BLACK);
g.drawOval(100, 150, 150, 150);
g.setColor(Color.BLACK);
g.drawString("0 Km/h", 100, 300);
g.drawString("240 km/h", 210, 300);
g.drawString("!!!Alerta!!!", 170, 90);
g.drawOval(170, 100, 20, 20);
g.setColor(Color.gray);
g.fillOval(100, 150, 150, 150);
Sensor s = new Sensor();
s.leerVel();
if (s.getVel()>0 & s.getVel()<80{
g.setColor(Color.BLUE);
g.fillArc(100, 150,150,150,225,-(320-(315-s.getVel())));
g.setColor(Color.WHITE);
g.drawString(s.getVel()+" Km/h", 150, 220);
g.setColor(Color.GREEN);
g.fillOval(170, 100, 20, 20);
}
if(s.getVel()>=80 & s.getVel()<150){
g.setColor(Color.YELLOW);
g.fillArc(100, 150,150,150,225,-(320-(315-s.getVel())));
g.setColor(Color.WHITE);
g.drawString(s.getVel()+" Km/h",150, 220);
g.setColor(Color.GREEN);
g.fillOval(170, 100, 20, 20);
}
if(s.getVel()>=150 & s.getVel()<=240){
g.setColor(Color.RED);
g.fillArc(100, 150,150,150,225,-(320-(315-s.getVel())));
g.setColor(Color.WHITE);
g.drawString(s.getVel()+" Km/h", 150,220);
g.setColor(Color.RED);
g.fillOval(170, 100, 20, 20);
}
}
public static void main(String args[]){
Interfase2 vel = new Interfase2();
vel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
public class Sensor {
private int vel;
public Sensor(){
}
public void setVel(int v) {
vel = v;
}
public int getVel(){
return vel;
}
public void leerVel(){
String aux;
aux = JOptionPane.showInputDialog("Ingrese la velocidad en Km/h");
vel = Integer.parseInt(aux);
}
public static void main(String args[]){
Sensor s = new Sensor();
s.leerVel();
System.out.println("Velocidad = "+s.getVel());
}
}
import javax.swing.*;
import java.awt.*;
public class Interfase2 extends JFrame{
public Interfase2(){
super("VELOCIMETRO");
setSize(400,400);
show();
}
public void paint(Graphics g){
super.paint(g);
g.setColor(Color.BLACK);
g.drawOval(100, 150, 150, 150);
g.setColor(Color.BLACK);
g.drawString("0 Km/h", 100, 300);
g.drawString("240 km/h", 210, 300);
g.drawString("!!!Alerta!!!", 170, 90);
g.drawOval(170, 100, 20, 20);
g.setColor(Color.gray);
g.fillOval(100, 150, 150, 150);
Sensor s = new Sensor();
s.leerVel();
if (s.getVel()>0 & s.getVel()<80{
g.setColor(Color.BLUE);
g.fillArc(100, 150,150,150,225,-(320-(315-s.getVel())));
g.setColor(Color.WHITE);
g.drawString(s.getVel()+" Km/h", 150, 220);
g.setColor(Color.GREEN);
g.fillOval(170, 100, 20, 20);
}
if(s.getVel()>=80 & s.getVel()<150){
g.setColor(Color.YELLOW);
g.fillArc(100, 150,150,150,225,-(320-(315-s.getVel())));
g.setColor(Color.WHITE);
g.drawString(s.getVel()+" Km/h",150, 220);
g.setColor(Color.GREEN);
g.fillOval(170, 100, 20, 20);
}
if(s.getVel()>=150 & s.getVel()<=240){
g.setColor(Color.RED);
g.fillArc(100, 150,150,150,225,-(320-(315-s.getVel())));
g.setColor(Color.WHITE);
g.drawString(s.getVel()+" Km/h", 150,220);
g.setColor(Color.RED);
g.fillOval(170, 100, 20, 20);
}
}
public static void main(String args[]){
Interfase2 vel = new Interfase2();
vel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
CALCULADORA
public class Operaciones {
static double resul;
public Operaciones(){
resul = 0;
}
public static double seno(double x){
resul = Math.sin(x);
return resul;
}
public static double coseno(double x){
resul = Math.cos(x);
return resul;
}
public static double tangente(double x){
resul = Math.tan(x);
return resul;
}
public static double logaritmo(double x){
if(x==0){
System.out.println("SOLO VALORES MAYORES A CERO");
resul = 0;
}else{
resul = Math.log(x);
}
return resul;
}
public static double suma(double x, double y){
resul = x+y;
return resul;
}
public static double resta(double x, double y){
resul = x-y;
return resul;
}
public static double multiplicacion(double x, double y){
resul = x*y;
return resul;
}
public static double division(double x, double y){
resul = x/y;
return resul;
}
}
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) {
// TODO add your handling code here:
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 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 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 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 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 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;
// End of variables declaration
}
static double resul;
public Operaciones(){
resul = 0;
}
public static double seno(double x){
resul = Math.sin(x);
return resul;
}
public static double coseno(double x){
resul = Math.cos(x);
return resul;
}
public static double tangente(double x){
resul = Math.tan(x);
return resul;
}
public static double logaritmo(double x){
if(x==0){
System.out.println("SOLO VALORES MAYORES A CERO");
resul = 0;
}else{
resul = Math.log(x);
}
return resul;
}
public static double suma(double x, double y){
resul = x+y;
return resul;
}
public static double resta(double x, double y){
resul = x-y;
return resul;
}
public static double multiplicacion(double x, double y){
resul = x*y;
return resul;
}
public static double division(double x, double y){
resul = x/y;
return resul;
}
}
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) {
// TODO add your handling code here:
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 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 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 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 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 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;
// End of variables declaration
}
MULTIPLICACION-TRANSPUESTA
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
}
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
}
SUMA MATRICES
package javaapplication1;
/**
*
*
*/
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 resultado = new Matriz ();
resultado.matriz[0][0]=((this.matriz[1][1]*this.matriz[2][2])-(this.matriz[2][1]*this.matriz[1][2]));
resultado.matriz[0][1]=((this.matriz[1][0]*this.matriz[2][2])-(this.matriz[2][0]*this.matriz[1][2]));
resultado.matriz[0][2]=((this.matriz[1][0]*this.matriz[2][1])-(this.matriz[2][0]*this.matriz[1][1]));
resultado.matriz[1][0]=((this.matriz[0][1]*this.matriz[2][2])-(this.matriz[2][1]*this.matriz[0][2]));
resultado.matriz[1][1]=((this.matriz[1][0]*this.matriz[2][2])-(this.matriz[2][0]*this.matriz[1][2]));
resultado.matriz[1][2]=((this.matriz[0][0]*this.matriz[2][1])-(this.matriz[2][0]*this.matriz[0][1]));
resultado.matriz[2][0]=((this.matriz[0][1]*this.matriz[1][2])-(this.matriz[1][1]*this.matriz[0][2]));
resultado.matriz[2][1]=((this.matriz[0][0]*this.matriz[1][2])-(this.matriz[1][0]*this.matriz[0][2]));
resultado.matriz[2][2]=((this.matriz[0][0]*this.matriz[1][1])-(this.matriz[1][0]*this.matriz[0][1]));
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);
}
}
}
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;
}
}
_____________________________________________________________________________________
public class Matriz {
public int numeroFilas;
public int numeroColumnas;
public double [][]matriz;
public Matriz(){}//nF es el numero de filas//nc es el numero de columnas
public Matriz(int nF, int nC){
numeroFilas = nF;
numeroColumnas = nC;
matriz = new double [numeroFilas][numeroColumnas];
for(int i=0; i<= numeroFilas; i++)
for(int j=0; j<= numeroColumnas ; j++)
matriz[i][j]=0;}//metodo de suma de matricespublic Matriz suma(Matriz b){Matriz resultado;//primero revisamos que las filas y las columnas sean iguales//
this referencia a un objeto que au 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<= b.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 multiplicacion de matrices//retorna una matriz resultado resta
public Matriz multiplicacion(Matriz b) {
Matriz resultado;
if(this.numeroFilas == b.numeroColumnas){
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;
}//devuelve el objeto matriz en texto para poderlo imprimir
}
public String toString(){
String aux="\n[\n";
for(int i=0; i<= this.numeroFilas; i++)
for(int j=0; j<= this.numeroColumnas; j++)
aux += matriz[i][j]+" ";
aux +="\n";aux+= "]";return aux;}
}
/**
*
*
*/
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 resultado = new Matriz ();
resultado.matriz[0][0]=((this.matriz[1][1]*this.matriz[2][2])-(this.matriz[2][1]*this.matriz[1][2]));
resultado.matriz[0][1]=((this.matriz[1][0]*this.matriz[2][2])-(this.matriz[2][0]*this.matriz[1][2]));
resultado.matriz[0][2]=((this.matriz[1][0]*this.matriz[2][1])-(this.matriz[2][0]*this.matriz[1][1]));
resultado.matriz[1][0]=((this.matriz[0][1]*this.matriz[2][2])-(this.matriz[2][1]*this.matriz[0][2]));
resultado.matriz[1][1]=((this.matriz[1][0]*this.matriz[2][2])-(this.matriz[2][0]*this.matriz[1][2]));
resultado.matriz[1][2]=((this.matriz[0][0]*this.matriz[2][1])-(this.matriz[2][0]*this.matriz[0][1]));
resultado.matriz[2][0]=((this.matriz[0][1]*this.matriz[1][2])-(this.matriz[1][1]*this.matriz[0][2]));
resultado.matriz[2][1]=((this.matriz[0][0]*this.matriz[1][2])-(this.matriz[1][0]*this.matriz[0][2]));
resultado.matriz[2][2]=((this.matriz[0][0]*this.matriz[1][1])-(this.matriz[1][0]*this.matriz[0][1]));
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);
}
}
}
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;
}
}
_____________________________________________________________________________________
public class Matriz {
public int numeroFilas;
public int numeroColumnas;
public double [][]matriz;
public Matriz(){}//nF es el numero de filas//nc es el numero de columnas
public Matriz(int nF, int nC){
numeroFilas = nF;
numeroColumnas = nC;
matriz = new double [numeroFilas][numeroColumnas];
for(int i=0; i<= numeroFilas; i++)
for(int j=0; j<= numeroColumnas ; j++)
matriz[i][j]=0;}//metodo de suma de matricespublic Matriz suma(Matriz b){Matriz resultado;//primero revisamos que las filas y las columnas sean iguales//
this referencia a un objeto que au 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<= b.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 multiplicacion de matrices//retorna una matriz resultado resta
public Matriz multiplicacion(Matriz b) {
Matriz resultado;
if(this.numeroFilas == b.numeroColumnas){
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;
}//devuelve el objeto matriz en texto para poderlo imprimir
}
public String toString(){
String aux="\n[\n";
for(int i=0; i<= this.numeroFilas; i++)
for(int j=0; j<= this.numeroColumnas; j++)
aux += matriz[i][j]+" ";
aux +="\n";aux+= "]";return aux;}
}
MOVIMIENTO RECTLINEO UNFORMEMENTE VARIADO
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author program
*/
public class MovRecUniVar {
Matriz posicion;
Matriz velocidad;
Matriz aceleracion;
public MovRecUniVar(){
}
public MovRecUniVar(Vector3D pos, Vector3D velo, Vector3D ace){
posicion = pos;
velocidad = velo;
aceleracion = ace;
}
public void calculaPosición(Vector3D r0, Vector3D vel,Vector3D a,double t){
posicion = r0.suma(vel.productoVectorEscalar(t)).suma(a.productoVectorEscalar(Math.pow(t,2)/2));
}
public void calculaVelocidad(Vector3D vel0, Vector3D a, double t){
velocidad = vel0.suma(a.productoVectorEscalar(t));
}
public void calculaAceleracion(Vector3D vel, Vector3D vel0, double t){
//aceleracion = a;
aceleracion = (vel.productoVectorEscalar(Math.pow(1,1)/2)).resta(vel0.productoVectorEscalar(Math.pow(1,1)/2));
}
public static void main(String args[]){
MovRecUniVar m = new MovRecUniVar();
Vector3D r0 = new Vector3D(5,0,0);
Vector3D v0 = new Vector3D(0,0,0);
Vector3D a = new Vector3D(3,0,0);
Vector3D v = new Vector3D(10,0,0);
double t = 2;
m.calculaPosición(r0, v0, a, t);
m.calculaVelocidad(v0,a, t);
m.calculaAceleracion(v,v0,t);
System.out.println("Posicion a los 2s para r0 = \n " +m.posicion+
"\nvelocidad a t = 2s\n"+m.velocidad+"\n aceleracion\n"+m.aceleracion );
}
}
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author program
*/
public class MovRecUniVar {
Matriz posicion;
Matriz velocidad;
Matriz aceleracion;
public MovRecUniVar(){
}
public MovRecUniVar(Vector3D pos, Vector3D velo, Vector3D ace){
posicion = pos;
velocidad = velo;
aceleracion = ace;
}
public void calculaPosición(Vector3D r0, Vector3D vel,Vector3D a,double t){
posicion = r0.suma(vel.productoVectorEscalar(t)).suma(a.productoVectorEscalar(Math.pow(t,2)/2));
}
public void calculaVelocidad(Vector3D vel0, Vector3D a, double t){
velocidad = vel0.suma(a.productoVectorEscalar(t));
}
public void calculaAceleracion(Vector3D vel, Vector3D vel0, double t){
//aceleracion = a;
aceleracion = (vel.productoVectorEscalar(Math.pow(1,1)/2)).resta(vel0.productoVectorEscalar(Math.pow(1,1)/2));
}
public static void main(String args[]){
MovRecUniVar m = new MovRecUniVar();
Vector3D r0 = new Vector3D(5,0,0);
Vector3D v0 = new Vector3D(0,0,0);
Vector3D a = new Vector3D(3,0,0);
Vector3D v = new Vector3D(10,0,0);
double t = 2;
m.calculaPosición(r0, v0, a, t);
m.calculaVelocidad(v0,a, t);
m.calculaAceleracion(v,v0,t);
System.out.println("Posicion a los 2s para r0 = \n " +m.posicion+
"\nvelocidad a t = 2s\n"+m.velocidad+"\n aceleracion\n"+m.aceleracion );
}
}
Suscribirse a:
Entradas (Atom)