Results 1 to 1 of 1
  1. #1
    Martino is offline Member
    Join Date
    Apr 2011
    Posts
    12
    Rep Power
    0

    Default Problem with the ProgressMonitor.

    Hello everyone,

    I have a small problem with the ProgressMonitor.

    I programmed it in my source code, because I would like to demonstrate the procedure of loading samples of a program I am building at the moment.

    The problem is that the ProgressMonitor does not appear, when the loading of the samples begins. I tried several ways to get the ProgressMonitor work, but I failed everytime.

    Can someone of you tell me what I have done wrong in the source code?

    Here is the source code. There are 2 parts.

    Code of loading the samples:
    ======================
    Java Code:
    class UpdateLoadSamples implements Runnable
        {
            public void run()
            {
                if (FUtils.progressMonitor.isCanceled())
                {
                    FUtils.progressMonitor.close();
                }
    
                int percent = (int) Math.round((si*1.0/numberOfToMakeSamples)*100.0);
    
                Utils.setProgressInProgressMonitor(percent);
            }
        }
    
    
    public void loadSamples(int numberOfMakingSamples) throws OutOfMemoryError, IOException, Exception
        {
    FUtils.startProgressMonitor("Samples are being loaded.");
    
            Timer timer = new Timer(100, this);
            for (si = numberOfMadeSamples - numberOfMakingSamples; si < numberOfMadeSamples; si++)
            {
                Sample sample = getSample(si);
    
                // Make Samples directory
                String sampleDirName = FUtils.convertStringToFileNameString(sample.getSampleName());
                setCurrentSampleDirectory(sampleDirName);
                this.projectSamplesDirsAndFiles.put(this.currentSampleDirectory, new TreeMap<String, String>());
    
                sampleDir = this.project +  getCurrentSampleDirectory();
                FUtils.makeDirs(sampleDir);
                sample.loadTableAndSaveToFile();
                            
            }
            timer.stop();
    }
    
    public void actionPerformed(ActionEvent e)
        {
            new UpdateLoadSamples();
        }
    ================================

    Here is the source code of showing and updating the ProgressMonitor:
    ================================================== ==

    The ProgressMonitor is situated in a static class, called FUtils, with the following static methods and variables:
    Java Code:
    public static ProgressMonitor progressMonitor;
    
        public static void startProgressMonitor(String message)
        {
            UIManager.put("ProgressMonitor.progressText", message);        
            FUtils.progressMonitor = new ProgressMonitor(null, "Monitoring Progress",
                    "Initializing . . .", 0, 100);
                    
        }
    
        public static void setProgressInProgressMonitor(int percent)
        {
            progressMonitor.setProgress(percent);
            progressMonitor.setNote(String.valueOf(percent) + " %");
        }

    ===============================================

    Thank you very much for your help in advance. I am looking forward!

    Martino
    Last edited by sunde887; 08-08-2011 at 02:57 PM. Reason: Added code tags, [code]...[/code]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •