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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
/////////////Main////////////////////
public class Main extends Object
{
public static void pause(long duree)
{
try
{
Thread.sleep(duree);
}
catch(InterruptedException e)
{
}
}
public static void main(String[] args)
{ // Creation d'un composant cuve
Animation cuve = new Animation();
Animation2 tuyau = new Animation2();
// Création d'un panel pour la cuve.
JPanel panel = new JPanel();
panel.add(cuve);
panel.add(tuyau);
// création d'une frame avec le Panel a l'intérieur
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setContentPane(panel);
f.pack();
f.setVisible(true);
// Fixer le niveau de la cuve.
tuyau.setNiveau1(0);
cuve.setNiveau(0);
//Animation du tuyau1
for(int j=tuyau.NIVEAU_MIN_TUYAU1; j<=tuyau.NIVEAU_MAX_TUYAU1; j++)
{
tuyau.setNiveau1(j);
pause(50);
}
//Animation de la cuve
for(int i=cuve.NIVEAU_MIN_CUVE; i<=cuve.NIVEAU_MAX_CUVE; i++)
{
cuve.setNiveau(i);
pause(50);
}
for(int i=cuve.NIVEAU_MAX_CUVE; i>=cuve.NIVEAU_MIN_CUVE;i--)
{
cuve.setNiveau(i);
pause(50);
}
}
}
//////////////////classe animation/////////////////////
import javax.swing.*;
import java.awt.*;
public class Animation extends Animation2
{
public final int NIVEAU_MIN_CUVE = 0;
public final int NIVEAU_MAX_CUVE = 100;
public int temp = NIVEAU_MIN_CUVE;
public Animation()
{
super();
this.setPreferredSize(new Dimension(1250,682));
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
//selectionne la largeur de l'écran
final int w = this.getWidth();
//selectionne la hauteur de l'écran
final int h = this.getHeight();
//Bulbdia est égal a la hauteur de fenetre/10
final int hauteurcuve = h*3/8;
final int stemHauteur = h - hauteurcuve;
//méthode pour la hauteur du fluide bleu
final int fluidHauteur = stemHauteur * (this.temp - NIVEAU_MIN_CUVE) / (NIVEAU_MAX_CUVE - NIVEAU_MIN_CUVE);
final int fluidHaut = stemHauteur - fluidHauteur;
//tuyaux
//fixer la couleur en bleu
//g.setColor(Color.BLUE);
//ajouter un composant de type rectangle
//50 position en x;570 = position en y;900 = taille en x;10 = taille en y;
//g.fillRect(50, 570, 900, 10);
//g.fillRect(50, 538, 10, 32);
//cuve
g.setColor(Color.BLUE);
g.fillRect(10, fluidHaut, 300, fluidHauteur);
g.setColor(Color.BLACK);
g.fillRect(10, 0, 300, fluidHaut);
}
//méthode qui sert a repeindre
public void setNiveau(int nouveauNiv)
{
this.temp = nouveauNiv;
this.repaint();
}
//méthode
public int getNiveau()
{
return this.temp;
}
}
/////////////Classe animation2////////////////
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.*;
public class Animation2 extends JComponent
{
public final int NIVEAU_MIN_TUYAU1 = 0;
public final int NIVEAU_MAX_TUYAU1 = 50;
public int temp2 = NIVEAU_MIN_TUYAU1;
public Animation2()
{
super();
this.setPreferredSize(new Dimension(1262,682));
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
//selectionne la largeur de l'écran
final int w = this.getWidth();
//selectionne la hauteur de l'écran
final int h = this.getHeight();
//Bulbdia est égal a la hauteur de fenetre/10
final int hauteurtuyau = h*3/8;
final int stem2Hauteur = h - hauteurtuyau;
//méthode pour la hauteur du fluide bleu
final int fluidHauteur2 = stem2Hauteur * (this.temp2 - NIVEAU_MIN_TUYAU1) / (NIVEAU_MAX_TUYAU1 - NIVEAU_MIN_TUYAU1);
final int fluidHaut2 = stem2Hauteur - fluidHauteur2;
//bassin de repli
g.setColor(Color.BLACK);
g.fillRect(650, 0, 10, fluidHaut2);
g.setColor(Color.BLUE);
g.fillRect(650, fluidHaut2, 10, fluidHauteur2);
//méthode qui sert a repeindre le tuyau
}
public void setNiveau1(int nouveauNiv1)
{
this.temp2 = nouveauNiv1;
this.repaint();
}
//méthode
public int getNiveau1()
{
return this.temp2;
}
} |
Partager