martes, 12 de enero de 2010

Pregunta 4, Trabajo Final

Ejercicio 4

To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Diego
*/

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

public class Velocimetro extends JFrame{
public Velocimetro(){
super("SENSOR DE VELOCIDAD");
setSize(600,400);
show();
}

public void paint(Graphics g){
int r,p,y;
super.paint(g);
g.setColor(Color.BLACK);{
g.drawRect(80, 150, 30, 150);
g.drawOval(370, 150, 150, 150);
}
g.setColor(Color.BLACK);{
g.drawString("0 Km/h", 80, 320);
g.drawString("280 km/h", 80, 140);
g.drawString("Alerta", 140, 90);
}
g.setColor(Color.ORANGE);{
g.fillOval(370, 150, 150, 150);
g.fillRect(80, 150, 30, 150);
}
g.setColor(Color.BLACK);{
g.drawLine(300, 0, 300, 400);
g.drawString("SENSOR DE VELOCIDAD LINEAL",60 , 50);
g.drawString("SENSOR DE VELOCIDADES", 370, 50);
g.drawString("PASTEL DE PORCENTAJES", 370,70);
}


Sensor s = new Sensor();
s.leerVelocidad();
if (s.getVelocidad()>0 & s.getVelocidad()<= 80){
g.setColor(Color.RED);
g.fillRect(80, 300-s.getVelocidad(), 30, s.getVelocidad());
g.setColor(Color.BLACK);
g.drawString(s.getVelocidad()+" km/h",150,220);
r=315-s.getVelocidad();
p=((s.getVelocidad()*100)/280);
g.setColor(Color.blue);
g.fillArc(370,150,150,150,225,-(320-r));
g.setColor(Color.black);
g.drawString(p+"%", 430, 220);
g.setColor(Color.GREEN);
g.fillOval(150, 100, 20, 20);//ovalao pequeño
}
if(s.getVelocidad()>80& s.getVelocidad()<=160){
g.setColor(Color.cyan);
g.fillRect(80, 150, s.getVelocidad(), -(150-s.getVelocidad()));
g.setColor(Color.BLACK);
g.drawString(s.getVelocidad()+" Km/h", 150, 220);
r=315-s.getVelocidad();
p=((s.getVelocidad()*100)/280);
g.setColor(Color.RED);
g.fillArc(370,150,150,150,225,-(320-r));
g.setColor(Color.black);
g.drawString(p+"%", 430, 220);
g.setColor(Color.yellow);
g.fillOval(150, 100, 20, 20);
}
if(s.getVelocidad()>160& s.getVelocidad()<=280){
g.setColor(Color.YELLOW);
g.fillRect(80, 150, 30, 150-s.getVelocidad());
g.setColor(Color.BLACK);
g.drawString(s.getVelocidad()+" Km/h",150, 220);
r=315-s.getVelocidad();
p=((s.getVelocidad()*100)/280);
g.setColor(Color.CYAN);
g.fillArc(370,150,150,150,225,-(420-r));
g.setColor(Color.black);
g.drawString(p+"%", 430, 220);
g.setColor(Color.RED);
g.fillOval(150, 100, 20, 20);

}

}

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


}

Pregunta 3, Trabajo Final


Ejercicio 3

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

public class Matriz {
public double[][] value=null;
protected String name=null;

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

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

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

jLabel9.setText("Matriz");

jLabel10.setText("Numero de Filas");

jLabel11.setText("Numero de columnas");

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

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

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jButton2)
.addGap(18, 18, 18)
.addComponent(jButton3)
.addContainerGap(880, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel2)
.addContainerGap(1045, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(345, 345, 345)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(672, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel6)
.addComponent(jLabel5)
.addComponent(jLabel8)
.addComponent(jLabel7)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jTextField4)
.addComponent(jTextField3)
.addComponent(jTextField2)
.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 135, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 352, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel9)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton4)
.addComponent(jLabel10)
.addComponent(jLabel11))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton5)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jTextField6, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 46, Short.MAX_VALUE)))))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(128, 128, 128)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 353, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton6)))))
.addGap(492, 492, 492))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(57, 57, 57)
.addComponent(jLabel2)
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2)
.addComponent(jButton3))
.addGap(45, 45, 45)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel3)
.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))
.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))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel7))
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel8)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(60, 60, 60)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton4)
.addComponent(jButton5)
.addComponent(jButton6))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel9)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel10)
.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel11)
.addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(113, 113, 113))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
.addContainerGap())))
);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(20, 20, 20))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.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 = 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("Transpuesta de Matrices: \n"+aux1+(m1.Transpuesta()).toString());



// TODO add your handling code here:
}

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

String aux = jTextField5.getText();
int nF = Integer.parseInt(aux);
aux = jTextField6.getText();
int nC = Integer.parseInt(aux);
m1= new Matriz(nF,nC);
m1.leer();
jTextArea2.setText("\nMATRIZ: \n"+(m1.toString())+"INVERSA DE MATRICES: \n"+(m1.Inversa().toString()));

}

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


}

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 jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.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
}

Pregunta 2, Trabajo Final

Que es un APPLET y su 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
package chuidiang.ejemplos;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JApplet;

/**
* Construye una ventana con un botón y una campo de texto. Cuando se pulsa
* el botón, escribe "Hola mundo" en el campo de texto.
*
* @author
*/
public class HolaMundoSwing extends JApplet
{
/** El botón */
private JButton b;

/** El campo de texto */
private JTextField t;

/**
* Crea la ventana, inicializa todo y la visualiza
*/
public void init()
{
// Nueva ventana. Se el pone un FlowLayout para que el botón y campo
// de texto quede alineados.
setLayout(new FlowLayout());

// Se crea el botón y se mete en la ventana
b = new JButton("Púlsame");
add (b);

// Se crea el campo de texto y se mete en la ventana
t = new JTextField(20);
add(t);

// Se le dice al botón qué tiene que hacer cuando lo pulsemos.
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
t.setText ("Hola mundo");
}
});
}

}

Esta es una forma sencilla de la representacion de un applet

Pregunta 1, Trabajo Final

Trabajo Final de Programación II

1 Describa las características principales de la librería AWT, SWING.

Librería AWT

*Son clases que permiten generar entornos con componentes gráficos comunes a todas las plataformas. El aspecto visual depende de la plataforma.
*Se trata de una biblioteca de clases Java para el desarrollo de Interfaces de Usuario Gráficas
*Los componentes AWT son aquellos proporcionados por las plataformas JDK 1.0 y 1.1. Aunque JDK 1.2 todavía soporta componentes AWT, La mayor diferencia entre los componentes AWT y los componentes Swing es que éstos últimos están implementados sin nada de código nativo.

Caracteristicas:
• 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)
• Alto nivel de abstracción respecto al entorno de ventanas en que se ejecute
• La arquitectura de la aplicación es dependiente del entorno de ventanas
• Es bastante dependiente de la máquina en que se ejecuta la aplicación
• Carece de un formato de recursos. No se puede separar el código de lo que es propiamente interface. No existe ningún diseñador de interfaces (todavía)

Estructura básica
Container, se encargan de contener en su interior al resto de componentes
Component, define el comportamiento de los componentes implementando métodos de gestión de eventos
Subclases directas
Button: Botón de pulsación o comando.
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.


Librería Swing

Swing es una biblioteca gráfica para Java. Incluye widgets para interfaz gráfica de usuario tales como cajas de texto, botones, desplegables y tablas.
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.

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 , se pueden leer y decodificar directamente los archivos de html, rtf .

Interfaces
Action
BoundedRangeModel
ButtonModel
CellEditor
ComboBoxEditor
ComboBoxModel
DesktopManager

ClasesAbstractAction
AbstractButton
AbstractCellEditor
AbstractListModel
ActionMap
BorderFactory
Box

Sensor de Velocidad

Clase Sensor

Import javax.swing.JOptionPane;

/**
*
* @author Diego
*/
public class Sensor {

private int velocidad;

public Sensor(){

}

public void setVelocidad(int v) {
velocidad = v;
}

public int getVelocidad(){
return velocidad;
}

public void leerVelocidad(){
String aux;
aux = JOptionPane.showInputDialog("Valor de la Velocidad");
velocidad = Integer.parseInt(aux);
}

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

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

public class Velocimetro extends JFrame{
public Velocimetro(){
setSize(400,400);
show();
}

public void paint(Graphics g){
int r;
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("280 km/h ", 210, 300);
g.drawString("!!!Alerta!!!", 170, 90);
g.drawOval(170, 100, 20, 20);

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


Sensor s = new Sensor();
s.leerVelocidad();
if (s.getVelocidad()>0 & s.getVelocidad()< 60){
g.setColor(Color.BLUE);

r=320-s.getVelocidad();
g.fillArc(100,150,150,150,225,-(320-r));
g.setColor(Color.BLACK);
g.drawString(s.getVelocidad()+" km/h", 150,220);


g.setColor(Color.GREEN);
g.fillOval(170, 100, 20, 20);//ovalao pequeño
}
if(s.getVelocidad()>=60 & s.getVelocidad()<100){
g.setColor(Color.cyan);
r=315-s.getVelocidad();
g.fillArc(100,150,150,150,225,-(320-r));
g.setColor(Color.BLACK);
g.drawString(s.getVelocidad()+" Km/h", 150, 220);
g.setColor(Color.GREEN);
g.fillOval(170, 100, 20, 20);
}
if(s.getVelocidad()>=100 & s.getVelocidad()<=280){
g.setColor(Color.CYAN);
r=315-s.getVelocidad();
g.fillArc(100, 150,150,150,225,-(320-r));
g.setColor(Color.BLACK);
g.drawString(s.getVelocidad()+" Km/h",150, 220);

g.setColor(Color.LIGHT_GRAY);
g.fillOval(170, 100, 20, 20);
}
}

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




Que es un APPLET y cuales son sus Caracteristicas

APPLET

Un appelet es un componente de una aplicacion que se ejecuta en un programa no puede trabajar de manera independiente
Java applet que es un código java que no consta el método main, utilizado principalmente para el trabajo de páginas web, es utilizado en una página HTML y representado por una pequeña pantalla gráfica dentro de ésta.

La ventaja principal de un applet
Consiste en que son menos dependientes del navegador incluso independientes del sistema operativo del ordenador entre otras podemos nombrar:

El applet puede trabajar en todas las versiones de Java
la mayor desventaja que tienen es que con los applets de Java no podremos hacer directamente cosas como abrir ventanas secundarias, controlar Frames, formularios, capas, etc. Otras como:

No puede iniciar la ejecución hasta que la JVM esté en funcionamiento, y esto puede tomar tiempo.

Cuando se ejecuta un applet, se llaman en este orden a los siguientes métodos:

init: son instrucciones para inicializar el applet.
start: llamado cuando se inicualiza un applet igual que el init pero tambien cuando se vuelve a ocupar un applet
paint: Se encarga de mostrar el contenido del applet. .


Para terminar la ejecución o pausarse se realiza los siguientes métodos:

stop: Suspende la ejecución del programa.
destroy: Cuando no se va a necesitar más el applet. Se usa para liberar recursos.