View Single Post
  #4 (permalink)  
Old 06-06-2008, 01:10 AM
Abdelhamidem Abdelhamidem is offline
Member
 
Join Date: Jun 2008
Posts: 2
Abdelhamidem is on a distinguished road
Thank you so much for your help, and all that work you've done. I've just found a solution, using a javax.Swing timer:

I changed the graphique1 class to this (by the way, i renamed it Graphique)
Code:
package montecarlo; import javax.swing.*; import javax.swing.event.*; import java.util.*; import java.awt.*; import java.awt.event.*; public class Graphique extends JPanel implements ActionListener { int X[] = new int[10000]; int Y[] = new int[10000]; int min, max; Random rand = new Random(); int randX = 0; int randY = 0; boolean functionDrawed = false; double zoom = 1; Integrale integrale; javax.swing.Timer t; public Graphique(Integrale I) { integrale = I; min = (int) I.borneMin - 100; max = (int) I.borneMax + 100; for (int i = min; i < max; i++) { X[i - min] = (int) zoom * i + 300; Y[i - min] = (int) (225 - zoom * I.evaluer(i)); } this.setPreferredSize(new java.awt.Dimension(600, 450)); repaint(); t = new javax.swing.Timer(100, this); t.start(); } @Override public void paintComponent(java.awt.Graphics g) { if (!functionDrawed) { g.setColor(new java.awt.Color(255, 255, 255)); g.fill3DRect(0, 0, 599, 449, true); g.setColor(new java.awt.Color(0, 0, 0)); g.drawPolygon(X, Y, max - min); functionDrawed = true; } randX = rand.nextInt(100) + -5 + 300; randY = 225 - rand.nextInt(100); if ((225 - zoom * integrale.evaluer((randX - 300) / zoom)) > randY) { g.setColor(new java.awt.Color(255, 0, 0)); } else { g.setColor(new java.awt.Color(0, 0, 255)); } g.drawLine(randX, randY, randX, randY); } public void actionPerformed(ActionEvent e) { repaint(); } } and it works perfectly!
Reply With Quote