martes, 12 de enero de 2010

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

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

public Matriz(){
}

public Matriz(int nF, int nC){
numeroFilas=nF;
numeroColumnas=nC;
matriz=new double[numeroFilas][numeroColumnas];
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; jresultado.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[\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()));
}
}

APPLET
public class Operaciones extends javax.swing.JApplet {
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());
}
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
}

velocimetro

package trabajofinal;

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

public class Sen {

private int velocidad;

public Sen(){
}
public void setVelocidad(int v) {
velocidad = v;
}
public int getVelocidad(){
return velocidad;
}
public void leerVelocidad(){
String aux;
aux = JOptionPane.showInputDialog("Velocidad en la que se encuentra");
velocidad = Integer.parseInt(aux);
}

public static void main(String args[]){
Sen s = new Sen();
s.leerVelocidad();
System.out.println("Velocidad = "+s.getVelocidad());
}
}

import javax.swing.*;
import java.awt.*;
import trabajofinal.Sen;
import java.text.DecimalFormat.*;
public class VelKm extends JFrame{
public VelKm(){
super("VELOCIMETRO");
setSize(600,400);
show();
}
@Override
public void paint(Graphics g){
int x,t,a;
super.paint(g);
g.setColor(Color.orange);{
g.drawOval(80, 150, 150, 150);
g.drawOval(370, 150, 150, 150);
}
g.setColor(Color.black);
g.drawString("0 Km/h", 80, 300);
g.drawString("Rapido", 200, 300);
g.drawString("Te vas a matar", 120, 90);
g.drawOval(150, 100, 20, 20);
g.setColor(Color.blue);
g.fillOval(80, 150, 150, 150);
g.setColor(Color.white);
g.fillOval(370, 150, 150, 150);
g.setColor(Color.black);{
g.drawLine(300, 0, 300, 400);
g.drawString("SENSOR DE VELOCIDAD LINEAL",75 , 50);
g.drawString("SENSOR DE VELOCIDAD", 370, 50);
g.drawString("PORCENTAJE", 400,70);

}

Sen s = new Sen();
s.leerVelocidad();
if (s.getVelocidad()>0 & s.getVelocidad()< 60){
g.setColor(Color.yellow);
x=320-s.getVelocidad();
g.fillArc(80,150,150,150,225,-(320-x));
g.setColor(Color.white);
g.drawString(s.getVelocidad()+" km/h", 150,220);
t=(s.getVelocidad()*100)/280;
a=(t*360)/100;
g.setColor(Color.blue);
g.fillArc(370, 150, 150, 150, 0, a);
g.setColor(Color.red);
g.drawString(t+"%", 430, 220);

g.setColor(Color.green);
g.fillOval(150, 100, 20, 20);// pequeño
}
if(s.getVelocidad()>=60 & s.getVelocidad()<100){
g.setColor(Color.orange);
x=315-s.getVelocidad();
g.fillArc(80,150,150,150,225,-(320-x));
g.setColor(Color.BLACK);
g.drawString(s.getVelocidad()+" Km/h", 150, 220);
t=(s.getVelocidad()*100)/280;
a=(t*360)/100;
g.setColor(Color.orange);
g.fillArc(370, 150, 150, 150, 0, a);
g.setColor(Color.black);
g.drawString(t+"%", 430, 220);
g.setColor(Color.GREEN);
g.fillOval(150, 100, 20, 20);
}


if(s.getVelocidad()>=100 & s.getVelocidad()<=280){
g.setColor(Color.YELLOW);
x=315-s.getVelocidad();
g.fillArc(80, 150,150,150,225,-(320-x));
g.setColor(Color.BLACK);
g.drawString(s.getVelocidad()+" Km/h",150, 220);

t=(s.getVelocidad()*100)/280;
a=(t*360)/100;
g.setColor(Color.green);
g.fillArc(370, 150, 150, 150, 0, a);
g.setColor(Color.black);
g.drawString(t+"%", 430, 220);
g.setColor(Color.RED);
g.fillOval(150, 100, 20, 20);
}

}
public static void main(String args[]){
VelKm vel = new VelKm();
vel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

Termometro

public class Sen {

private int temperatura;

public Sen(){

}

public void setTemperatura(int v) {
temperatura = v;
}

public int getTemperatura(){
return temperatura;
}

public void leerTemperatura(){
String aux;
aux = JOptionPane.showInputDialog("Temperatura");
temperatura = Integer.parseInt(aux);
}

public static void main(String args[]){
Sen s = new Sen();
s.leerTemperatura();
System.out.println("Temperatura = "+s.getTemperatura());
}

}

import javax.swing.*;
import java.awt.*;
import trabajofinal.Sen;
import java.text.DecimalFormat.*;

public class TerMo extends JFrame{
public TerMo(){
super("TERMOMETRO");
setSize(300,400);
show();
}

@Override
public void paint(Graphics g){
int x,t,a;
super.paint(g);
g.setColor(Color.red);{
g.drawOval(80, 150, 150, 150);

}
g.setColor(Color.black);
g.drawString("0 ºC", 80, 300);
g.drawString("Calientisimo", 200, 300);
g.drawString("¡¡Vea la temperatura¡¡", 100, 90);
g.drawOval(150, 100, 20, 20);
g.setColor(Color.white);
g.fillOval(80, 150, 150, 150);


g.setColor(Color.black);{
g.drawLine(300, 0, 300, 400);
g.drawString("TERMOMETRO",110 , 50);


}


Sen s = new Sen();
s.leerTemperatura();
if (s.getTemperatura()>0 & s.getTemperatura()< 60){
g.setColor(Color.yellow);

x=320-s.getTemperatura();

g.fillArc(80,150,150,150,225,-(320-x));
g.setColor(Color.orange);
g.drawString(s.getTemperatura()+"ºC", 150,220);



g.setColor(Color.yellow);
g.fillOval(150, 100, 20, 20);//ovalao pequeño


}
if(s.getTemperatura()>=60 & s.getTemperatura()<100){
g.setColor(Color.orange);
x=315-s.getTemperatura();
g.fillArc(80,150,150,150,225,-(320-x));

g.setColor(Color.BLACK);
g.drawString(s.getTemperatura()+" ºC", 150, 220);
t=(s.getTemperatura()*100)/280;
a=(t*360)/100;



g.setColor(Color.orange);
g.fillOval(150, 100, 20, 20);
}


if(s.getTemperatura()>=100 & s.getTemperatura()<=280){
g.setColor(Color.RED);
x=315-s.getTemperatura();
g.fillArc(80, 150,150,150,225,-(320-x));
g.setColor(Color.BLACK);
g.drawString(s.getTemperatura()+" ºC",150, 220);

t=(s.getTemperatura()*100)/280;
a=(t*360)/100;





g.setColor(Color.RED);
g.fillOval(150, 100, 20, 20);
}

}

public static void main(String args[]){
TerMo vel = new TerMo();
vel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}



}

Definicion de applet, funcionamiento

QUE ES UN APPLET

*Los applets de Java están programados en Java y precompilados, es por ello que la manera de trabajar de éstos varía un poco con respecto a los lenguajes de script como Javascript.
*Un applet es un componente de una aplicación que se ejecuta en el contexto de otro programa, por ejemplo un navegador web.
*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.
*Un applet es una mini-aplicación escrita en Java. No tienen ventana propia, se ejecutan en la ventana del browser y tienen importantes restricciones de seguridad, las cuales se comprueban al llegar al browser: sólo pueden leer y escribir en el servidor del que han venido y solo pueden acceder a una limitada información en el servidor en el que se están ejecutando.

Métodos que controlan la ejecución de un APPLET
Método init ( )

Se llama automáticamente en cuanto el browser carga el applet. Este método se ocupa de las tareas de inicialización.

Método start ( )

Se llama automáticamente en cuanto el applet se hace visible, después de haber sido inicializado. Es habitual crear threads en este método para aquellas tareas que, por el tiempo que requieren, dejarían sin recursos al applet o incluso al browser. Un ejemplo de estás son las animaciones.

Método stop ( )

Se llama de forma automática al ocultar el applet, detiene la ejecución.

Método destroy ( )

Se llama a este método cuando el applet va a ser descargado para liberar los recursos que tenga reservados, hace limpieza final.

EJEMPLO
/**
* Applet Hello World
*/
import java.applet.Applet;
import java.awt.Graphics;

public class AppletSimple extends Applet{
public void paint(Graphics g){
g.drawString("Hola Mundo en Java", 50, 25);
}
}

Caracteristicas awt y swing




• Son clases que permiten generar entornos con componentes gráficos comunes a todas las plataformas, y gestionar eventos de teclado y ratón, entre otros. El aspecto visual depende de la plataforma.
• Se trata de una biblioteca de clases Java para el desarrollo de Interfaces de Usuario Gráficas
Caracteristicas:
Genera interfaces gráficas, independientemente de la plataforma en que se ejecute la aplicación.
• Los Contenedores contienen Componentes, que son los controles básicos
• No se usan posiciones fijas de los Componentes, sino que están situados a través de una disposición controlada (layouts)
• El común denominador de más bajo nivel se acerca al teclado, ratón y manejo de eventos
• Alto nivel de abstracción respecto al entorno de ventanas en que se ejecute la aplicación (no hay áreas cliente, ni llamadas a X, ni hWnds, etc.)
• La arquitectura de la aplicación es dependiente del entorno de ventanas, en vez de tener un tamaño fijo
• Es bastante dependiente de la máquina en que se ejecuta la aplicación (no puede asumir que un diálogo tendrá el mismo tamaño en cada máquina)
• Carece de un formato de recursos. No se puede separar el código de lo que es propiamente interface. No hay ningún diseñador de interfaces (todavía)

Estructura básica
Container, se encargan de contener en su interior al resto de componentes e, incluso, a otros contenedores.
Component, define el comportamiento de los componentes implementando métodos de gestión de eventos, y también la presentación de los mismos mediante la definición de sus tamaños, posiciones, colores y fuentes entre otras.
Subclases directas
Button: Botón de comando o de pulsación.
Canvas: Lienzo o área de dibujo.
Checkbox: Caja de chequeo o de comprobación.
CheckboxGroup: Grupo de cajas de chequeo.
Choice: Lista de desplegable o de selección.
Container: Contenedor.
Label: Etiqueta de texto.
List: Lista de datos.
Scrollbar: Barra de desplazamiento.
TextComponent: Componente de texto.
Ejemplo:
/*********************************************************/
/* Autor: Rafael Hernamperez Martin */
/* Fecha: 07-05-2000 */
/* Obj : Ejemplo basico de AWT */
/*********************************************************/
import java.awt.*;
import java.applet.Applet;
public class EjemploAWT1 extends Applet
{
public void init ()
{
// Creacion de un boton
Button btnBoton = new Button ("Boton");
add (btnBoton);
}
} // Fin de la clase EjemploAWT1


Swing
•Era el nombre clave del proyecto que desarrolló los nuevos componentes. Aunque no es un nombre oficial, frecuentemente se usa para referirse a los nuevos componentes y al API relacionado. Está inmortalizado en los nombres de paquete del API Swing, que empiezan con "javax.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.
Versiones de swing
 Swing 0.2
 Swing 1.0.3
 Swing 1.1 Beta
 Swing 1.1 Beta 3
 Swing 1.1
Caracteristicas
• Swing cambia completamente la gestión del texto. Se pueden crear texto de colores, con distintos tipos de caracteres.
• Es posible introducir incluso imágenes y, además, se pueden leer y decodificar directamente los archivos de html, rtf (Un primo de .doc).
• Es necesario gestionar los sucesos. Para esto está el paquete de java.awt.event que gestiona dichos sucesos.


Interfaces
Action
BoundedRangeModel
ButtonModel
CellEditor
ComboBoxEditor
ComboBoxModel
DesktopManager

Clases
AbstractAction
AbstractButton
AbstractCellEditor
AbstractListModel
ActionMap
BorderFactory
Box

Ejemplo de lo que podemos hacer con un apllet

martes, 5 de enero de 2010

OperacionesConMatrices

public class Matriz {
public int numeroFilas;
public int numeroColumnas;
public int [][]matriz;
public Matriz(){
}
public Matriz(int nF, int nC){
numeroFilas=nF;
numeroColumnas=nC;
matriz=new int[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;
}
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;
}
}
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 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]=Integer.parseInt(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;
}
}


private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String aux = jTextField1.getText();
int nF = Integer.parseInt(aux);
aux = jTextField2.getText();
int nC = Integer.parseInt(aux);
m1 = new Matriz(nF,nC);
m1.leer();
aux = jTextField3.getText();
nF = Integer.parseInt(aux);
aux = jTextField4.getText();
nC = Integer.parseInt(aux);
m2 = new Matriz(nF,nC);
m2.leer();
jTextArea1.setText("Suma: \n"+(m1.suma(m2)).toString());
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String aux = jTextField1.getText();
int nF = Integer.parseInt(aux);
aux = jTextField2.getText();
int nC = Integer.parseInt(aux);
m1 = new Matriz(nF,nC);
m1.leer();
aux = jTextField3.getText();
nF = Integer.parseInt(aux);
aux = jTextField4.getText();
nC = Integer.parseInt(aux);
m2 = new Matriz(nF,nC);
m2.leer();
jTextArea1.setText("Resta: \n"+(m1.resta(m2)).toString());
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here
String aux = jTextField1.getText();
int nF = Integer.parseInt(aux);
aux = jTextField2.getText();
int nC = Integer.parseInt(aux);
m1 = new Matriz(nF,nC);
m1.leer();
jTextArea1.setText("La transpuesta de la matriz uno es: \n"+(m1.Transpuesta()).toString());
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String aux = jTextField1.getText();
int nF = Integer.parseInt(aux);
aux = jTextField2.getText();
int nC = Integer.parseInt(aux);
m1 = new Matriz(nF,nC);
m1.leer();
aux = jTextField3.getText();
nF = Integer.parseInt(aux);
aux = jTextField4.getText();
nC = Integer.parseInt(aux);
m2 = new Matriz(nF,nC);
m2.leer();
jTextArea1.setText("Multiplicacion de Matrices: \n"+(m1.Multiplicacion(m2)).toString());
}
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.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
}

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
}