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


}

No hay comentarios:

Publicar un comentario