Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Simulazione di Fisica 003 - Moto delle molecole di un gas - RenderClock.java

RenderClock.java

Caricato da: Matthew
Scarica il programma completo

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. import java.awt.*;
  6. import java.awt.image.*;
  7.  
  8. /**
  9.  *
  10.  * @author Matthew
  11.  */
  12.  
  13. public class RenderClock extends Thread
  14. {
  15.     public double Round(double numero, int cifre)
  16.     {
  17.         java.math.BigDecimal bd = new java.math.BigDecimal(numero);
  18.         bd = bd.setScale(cifre, java.math.BigDecimal.ROUND_HALF_UP);
  19.  
  20.         return bd.doubleValue();
  21.  
  22.     }
  23.  
  24.     int width, height;
  25.     BufferedImage bi;
  26.     Graphics2D g0,g0p;
  27.  
  28.     public RenderClock(Graphics g)
  29.     {
  30.        width = 336;
  31.        height = 336;
  32.        g0p = (Graphics2D)g;
  33.     }
  34.  
  35.  
  36.  
  37.  
  38.     public @Override void run()
  39.     {
  40.          bi = new BufferedImage(width, height, BufferedImage.SCALE_FAST);
  41.          g0 = bi.createGraphics();
  42.          g0.setBackground(Color.WHITE);
  43.        
  44.          double h, hg, volume;
  45.  
  46.          try
  47.          {
  48.              for(;;)
  49.              {
  50.                 g0.clearRect(0, 0, width, height);
  51.  
  52.                
  53.                
  54.  
  55.                
  56.                 volume = Bicchiere.volume;
  57.  
  58.                 h=volume/Bicchiere.S;
  59.                
  60.                 hg=274*h*10;
  61.  
  62.                 hg=284-hg;
  63.  
  64.                 g0.setColor(Color.DARK_GRAY);
  65.                 g0.fillRect(0, 300, 336, 18);
  66.                 g0.fillRect(0, 0, 18, 318);
  67.                 g0.fillRect(318, 0, 18, 318);
  68.                 g0.setColor(Color.CYAN);
  69.                 g0.fillRect(18, 0, 300, 300);
  70.                 //g0.drawString(String.valueOf(Round(Bicchiere.pressione*Bicchiere.S/9.806,3))+" kg",36, (int)hg-20);
  71.                
  72.                 g0.setColor(Color.BLUE);
  73.  
  74.                 for(int i=0; i<Bicchiere.npart; i++)
  75.                 {
  76.                     g0.fillOval(Bicchiere.molecola[i].getXg(), Bicchiere.molecola[i].getYg(), 4,4);
  77.                 }
  78.  
  79.  
  80.                 Bicchiere.txtTempo.setText(String.valueOf(Round(Bicchiere.tempo, 8)));
  81.                 Bicchiere.txtV.setText(String.valueOf(volume));
  82.                
  83.                 Bicchiere.txtP.setText(String.valueOf(Bicchiere.P));
  84.  
  85.                 Bicchiere.txtN.setText(String.valueOf(Round(Bicchiere.moli, 3)));
  86.  
  87.                 g0p.drawImage(bi, null,0,0);
  88.                 Thread.sleep(10);
  89.              }
  90.          }
  91.          catch(InterruptedException e)
  92.          {
  93.  
  94.          }
  95.          
  96.  
  97.          
  98.  
  99.     }
  100.  
  101.    
  102. }