IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 Java Discussion :

[JProgressBar] Actualiser la barre


Sujet :

Java

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Mai 2017
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Lycéen
    Secteur : Enseignement

    Informations forums :
    Inscription : Mai 2017
    Messages : 1
    Points : 1
    Points
    1
    Par défaut [JProgressBar] Actualiser la barre
    Bonjour,
    J'aimerai aujourd’hui avoir vos conseils pour un programme d'affichage de fractale que je suis en train de coder. Lors du calcul des points qui forment ma fractale, je souhaite afficher une barre de progression qui détermine le pourcentage accompli. Seulement il se passe que malgré le fait que mon setValue soit dans un Thread avec mon process, je n'ai pas trouvé de moyen pour que la barre soit actualisée ( elle s'affiche à sans pourcentage puis à 100% une fois le process finit). Je ne doute pas un instant que je m'y prends comme un pied et souhaite donc avoir l'avis de gens plus expérimentés que moi

    Code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.HashSet;
    import java.util.concurrent.Future;
     
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JProgressBar;
    import javax.swing.SwingUtilities;
    import javax.swing.Timer;
     
    import javafx.concurrent.Task;
     
    public class FractaleCalcul extends JFrame{
     
     
     
     
    	  private Thread t;
    	  private HashSet data;
    	  private JProgressBar bar;
    	  private int progress;
     
    	  private int choice;
    	  private int number;
     
     
     
     
    	  public FractaleCalcul(int choice,int number){ 
     
     
     
     
    		this.choice = choice;
    		this.number = number;
     
    	    this.setSize(300, 80);
     
    	    this.setTitle("*** Calcul des points ***");
     
    	    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
    	    this.setLocationRelativeTo(null);      
     
     
    	    bar  = new JProgressBar();
     
    	    bar.setMaximum(this.number);
     
    	    bar.setMinimum(0);
     
    	    bar.setStringPainted(true);
     
     
    	    this.getContentPane().add(bar, BorderLayout.CENTER);
    	    t = new Thread(new Traitement(this.choice,this.number));
            t.start();  
            this.setVisible(true);
            while(this.progress<this.number){
            	try {
    				Thread.sleep(10);
    			} catch (InterruptedException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
            }
            PanelDraw.draw(data);
     
     
    	  }
    	  public HashSet getData(){
    		  return this.data;
    	  }
     
    	    public int getProgress(){
    	    	return this.progress;
    	    }
     
     
    	  class Traitement implements Runnable{ 
    		 private int choice;
    		 private int number;
     
    		 public Traitement(int c,int n){
    			 this.choice = c;
    			 this.number = n;
    		 }
     
     
    	    public void run(){
     
    	    	HashSet<Matrix> hs = new HashSet();
    	    	float[][]tab = {{(float)0},{(float) 0}};
    			Matrix matriceU = new Matrix(2,1,tab); 
    			for(int k=0;k<=this.number;k++){
    				matriceU = DragonCalcul.DragonCalc(matriceU);
    				hs.add(matriceU);
    				bar.setValue(k);
    				progress = k;
    			}
    	    	data = hs;
    	    } 
     
     
     
     
     
    	  } 
     
    }
    Main :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
     
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
     
    import com.sun.javafx.geom.Matrix3f;
     
     
     
    	public class Fenetre extends JFrame {
     
    		  private JButton bouton = new JButton("Rentrez les informations");
     
     
    		  public Fenetre(){      
     
    		    this.setTitle("Informations");
     
    		    this.setSize(300, 100);
     
    		    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
    		    this.setLocationRelativeTo(null);      
     
    		    this.getContentPane().setLayout(new FlowLayout());
     
    		    this.getContentPane().add(bouton);
     
    		    bouton.addActionListener(new ActionListener(){
     
    		      public void actionPerformed(ActionEvent arg0) {
     
    		        ZDialog zd = new ZDialog(null, "Informations", true);
    		        ZDialogInfo zInfo = zd.showZDialog(); 
    		       FractaleCalcul calc = new FractaleCalcul(zInfo.getChoice(),zInfo.getNumber());		 
     
     
    		      }         
     
    		    });      
     
    		    this.setVisible(true);      
     
    		  }
     
    	public static void main(String[] args) {
     
     
    	    Fenetre fen = new Fenetre();
     
     
    	}  
    }

  2. #2
    Modérateur
    Avatar de wax78
    Homme Profil pro
    Chef programmeur
    Inscrit en
    Août 2006
    Messages
    4 074
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Belgique

    Informations professionnelles :
    Activité : Chef programmeur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2006
    Messages : 4 074
    Points : 7 978
    Points
    7 978
    Par défaut
    Salut,

    Tu bloque le thread EDT en faisant de cette manière ce qui n'est pas une bonne idée.

    Je te conseil d'essayer de lire http://gfx.developpez.com/tutoriel/j...ing-threading/
    (Les "ça ne marche pas", même écrits sans faute(s), vous porteront discrédit ad vitam æternam et malheur pendant 7 ans)

    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

Discussions similaires

  1. actualiser une barre deroulante
    Par Flash_Over dans le forum Requêtes et SQL.
    Réponses: 2
    Dernier message: 27/06/2008, 13h29
  2. [JProgressBar/Thread] Ma barre apparaît après :(
    Par Zanton dans le forum AWT/Swing
    Réponses: 5
    Dernier message: 13/06/2006, 15h30
  3. [JProgressBar] Afficher barre d'attente pendant traitement
    Par Regis.C dans le forum Composants
    Réponses: 10
    Dernier message: 02/09/2005, 16h43
  4. Actualisation d'une barre d'outil
    Par zoom61 dans le forum IHM
    Réponses: 2
    Dernier message: 07/03/2005, 10h28
  5. Barre de progression JProgressBar
    Par sixkiller dans le forum Composants
    Réponses: 7
    Dernier message: 08/12/2004, 11h33

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo