0

I want to ask how to give jProgressBar in my code. i used netbeans interface. progressBar will end after it reach maximum_iteration. jProgressBar already in other class. how can i fix it? Thank you. Please help.

train() is placed in other class.

public void train(){
    for(int iteration=0; iteration<this.max_iteration; iteration++){
        //int percent = (iteration/this.max_iteration) * 100;
        //cs.jProgressBar1.setValue(percent);
        for(int index=0; index<this.hms; index++){
            Node[] newChord = {};
            double random = Math.random();
            /*process HS*/
            if(this.original_chord != null){
                // ensure the fist note of the new chord is not altered
                newChord[0].notes = new int[first_chord_notes.length];
                for(int j=0; j<first_chord_notes.length; j++){
                    newChord[0].notes[j] = first_chord_notes[j];
                }
            }
            // evaluate new chord and substitute the worst one in hs if new chord is better
            double newFitness = this.nodeListFitness(this.original_chord, newChord);
            int worstIndex = this.worst_index();
            double worstFitness = this.fitness[worstIndex];
            if(newFitness > worstFitness){
                this.hm[worstIndex] = newChord;
                this.fitness[worstIndex] = newFitness;
            }
        }
        System.out.println("Harmony Memory " + (iteration+1));
        this.debug();
        System.out.println("");
        //JProgressBar jProgressBar1 = new JProgressBar();
        //cs.jProgressBar1.setValue(iteration);
        //cs.jProgressBar1.setEnabled(true);


    }
}
Juxhin
  • 5,068
  • 8
  • 29
  • 55
Theresia
  • 33
  • 5
  • possible duplicate of [Can a progress bar be used in a class outside main?](http://stackoverflow.com/questions/4637215/can-a-progress-bar-be-used-in-a-class-outside-main) – trashgod Jun 02 '15 at 14:15

1 Answers1

0

I'm not sure at 100% but a Swing Component can be updated only inside the EventDispatcherThread, which is the Thread that run the GUI. For this reason, it will probably be better that you call the method train() inside you GUI, so it run into the EDT. Also, I can't understand why do you call the constructor of the JProgessBar, if you say that it is already in other class, probably the other class (I image it is the GUI) has already created a new instance of the progress bar.

Nicola Bena
  • 98
  • 1
  • 1
  • 10