lunes, 11 de enero de 2010

Velocimetro dos

import javax.swing.*;
public class sensordatos {private int vel;
public sensordatos(){
}
public void setVel(int v) {
vel = v;
}
public int getVel(){
return vel;
}
public void leerVel(){
String aux;
aux = JOptionPane.showInputDialog("velocidad en [Km/h]");
vel = Integer.parseInt(aux);
}
public static void main(String args[]){
sensordatos s = new sensordatos();
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.blue);
g.drawString("0 [Km/h]", 100, 300);
g.setColor(Color.red);
g.drawString("240 [km/h]", 210, 300);
g.setColor(Color.black);
g.drawOval(170, 100, 20, 20);
g.setColor(Color.white);
g.fillOval(100, 150, 150, 150);
sensordatos s = new sensordatos();
s.leerVel();
if (s.getVel()>0 & s.getVel()<80){
g.setColor(Color.green);
g.fillArc(100, 150,150,150,225,-(320-(315-s.getVel())));
g.setColor(Color.LIGHT_GRAY);
g.drawString(s.getVel()+" Km/h", 150, 220);
g.setColor(Color.GREEN);
g.fillOval(170, 100, 20, 20);
g.setColor(Color.green);
g.drawString("Vas bien a ="+s.getVel()+"[km/h]", 170, 90);
}
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.lightGray);
g.drawString(s.getVel()+" Km/h",150, 220);
g.setColor(Color.GREEN);
g.fillOval(170, 100, 20, 20);
g.setColor(Color.yellow);
g.drawString("¡¡¡Cuidado vas a= "+s.getVel()+"[km/h]!!!!!", 170, 90);
}
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.lightGray);
g.drawString(s.getVel()+" Km/h", 150,220);
g.setColor(Color.RED);
g.fillOval(170, 100, 20, 20);
g.setColor(Color.red);
g.drawString("!!!PELIGRO vas a= "+s.getVel()+"[km/h]!!!!", 170, 90);
}




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

No hay comentarios:

Publicar un comentario