1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| package test;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
/**
* @author Florian
*/
public class Anemometre extends JPanel {
/**
*
*/
private static final long serialVersionUID = 1L;
private Aiguille indicVitesse;
private int[][] positionDepart={{95,100},{105,100},{100,0}};
private double v=0.0;
private double angleV=Math.PI/120;
public Anemometre(int x, int y, int longueur, int hauteur){
this.setBounds(x,y, longueur, hauteur);
indicVitesse= new Aiguille(positionDepart);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
if (SwingUtilities.isEventDispatchThread()){
System.out.println("Dans EDT, Anemometre");
} else {System.out.println("Pas EDT, Anemometre");}
Graphics2D comp2D=(Graphics2D) g;
comp2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
comp2D.setColor(Color.black);
comp2D.fillOval(1,1,200,200);
comp2D.setColor(Color.white);
comp2D.fillArc(10, 10, 180, 180, -165+90, +105);
comp2D.setColor(Color.green);
comp2D.fillArc(20, 20, 160, 160, -217+90, 147);
comp2D.setColor(Color.orange);
comp2D.fillArc(20, 20, 160, 160, -270+90, 53);
comp2D.setColor(Color.black);
comp2D.fillArc(20, 20, 160, 160, -75+90, 147);
comp2D.setColor(Color.black);
comp2D.fillArc(30,30,140,140, 0, 360);
comp2D.setColor(Color.white);
for (int i=40;i<210;i=i+10)
{
comp2D.setFont(new java.awt.Font("Comic Sans MS", java.awt.Font.BOLD, 8));
comp2D.drawString(String.valueOf(i),
100+(int) ((70+(2*i)/40)*Math.cos(-Math.PI/2+i*3*Math.PI/360)),
100+(int) (70*Math.sin(-Math.PI/2+i*3*Math.PI/360)));
if(i==180){
comp2D.setColor(Color.red);
comp2D.drawLine(100+(int) (80*Math.cos(-Math.PI/2+i*3*Math.PI/360)),
100+(int) (80*Math.sin(-Math.PI/2+i*3*Math.PI/360)),
100+(int) (100*Math.cos(-Math.PI/2+i*3*Math.PI/360)),
100+(int) (100*Math.sin(-Math.PI/2+i*3*Math.PI/360)));
comp2D.setColor(Color.white);
}
else{
comp2D.drawLine(100+(int) (80*Math.cos(-Math.PI/2+i*3*Math.PI/360)),
100+(int) (80*Math.sin(-Math.PI/2+i*3*Math.PI/360)),
100+(int) (100*Math.cos(-Math.PI/2+i*3*Math.PI/360)),
100+(int) (100*Math.sin(-Math.PI/2+i*3*Math.PI/360)));}
}
for (int i=45;i<205;i=i+10)
{
comp2D.drawLine(100+(int) (90*Math.cos(-Math.PI/2+i*3*Math.PI/360)),
100+(int) (90*Math.sin(-Math.PI/2+i*3*Math.PI/360)),
100+(int) (100*Math.cos(-Math.PI/2+i*3*Math.PI/360)),
100+(int) (100*Math.sin(-Math.PI/2+i*3*Math.PI/360)));
}
// indicVitesse.Rotation(v*angleV);
indicVitesse.affichageEcran(comp2D);
}
/**
* @return
* @uml.property name="v"
*/
public double getV() {
return v;
}
/**
* @param v
* @uml.property name="v"
*/
public void setV(double v) {
this.v = v;
}
public static void main(String []args){
JFrame fenetre=new JFrame("Anémomètre");
fenetre.setBounds(0,0,200, 200);
Anemometre anemometre = new Anemometre(50, 50, 100, 100);
fenetre.getContentPane().setLayout(new BorderLayout());
fenetre.getContentPane().add(anemometre, BorderLayout.CENTER);
fenetre.getContentPane().add(new Controleur(anemometre), BorderLayout.SOUTH);
fenetre.pack();
fenetre.setVisible(true);
}
public Aiguille getIndicVitesse() {
return indicVitesse;
}
} |
Partager