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);
}
}
martes, 12 de enero de 2010
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario