Results 1 to 4 of 4
  1. #1
    SebScoFr is offline Member
    Join Date
    Nov 2008
    Posts
    3
    Rep Power
    0

    Default [SOLVED] Netbeans Desktop App & JProgressBar

    Hi everyone,

    I've been looking for solutions for my problem on the internet for hours without any success so I hope someone here can help me.

    I'm working on an encryption program on Java implementing the RSA algorithm.
    I'm using a NetBeans Desktop Application to develop this application.

    Since the encryption process might take a while depending on which files the user wants to encrypt, I'm using a Task that realizes the process in another thread within the doInBackground() method.

    Everything works fine except that I'd like to display the process progress in the progress bar provided by default in the desktop application. But for some reasons, nothing happens :(

    Here is the code:

    Generated by Netbeans, no need to modify it (?)
    Java Code:
    public class RSAProject extends FrameView {
        
        public RSAProject(SingleFrameApplication app) {
            super(app);
     
            initComponents();
     
            // status bar initialization - message timeout, idle icon and busy animation, etc
            ResourceMap resourceMap = getResourceMap();
            int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
            messageTimer = new Timer(messageTimeout, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    statusMessageLabel.setText("");
                }
            });
            messageTimer.setRepeats(false);
            int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
            for (int i = 0; i < busyIcons.length; i++) {
                busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
            }
            busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                    statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
                }
            });
            idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
            statusAnimationLabel.setIcon(idleIcon);
            progressBar.setVisible(true);
     
            // connecting action tasks to status bar via TaskMonitor
            TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
            taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
                @Override
                public void propertyChange(java.beans.PropertyChangeEvent evt) {
                    String propertyName = evt.getPropertyName();
                    System.out.println(propertyName);
                    if ("started".equals(propertyName)) {
                        if (!busyIconTimer.isRunning()) {
                            statusAnimationLabel.setIcon(busyIcons[0]);
                            busyIconIndex = 0;
                            busyIconTimer.start();
                        }
                        progressBar.setIndeterminate(true);
                    } else if ("done".equals(propertyName)) {
                        busyIconTimer.stop();
                        statusAnimationLabel.setIcon(idleIcon);
                        progressBar.setValue(0);
                    } else if ("message".equals(propertyName)) {
                        String text = (String)(evt.getNewValue());
                        statusMessageLabel.setText((text == null) ? "" : text);
                        messageTimer.restart();
                    } else if ("progress".equals(propertyName)) {
                        int value = (Integer)(evt.getNewValue());
                        progressBar.setIndeterminate(false);
                        progressBar.setValue(value);
                    }
                }
            });
        }
    The button which start the Task
    Java Code:
    private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {
        this.startEncrypt().execute;
    }
    And the Task itself
    Java Code:
        @Action
        public Task startEncrypt() {
            return new StartEncryptTask(getApplication());
        }
     
        private class StartEncryptTask extends Task<Void, Void> {
            StartEncryptTask(org.jdesktop.application.Application app) {
                super(app);
            }
            
            @Override
            protected Void doInBackground() {
                try {
                    //specific code for encryption
                }
                catch(java.lang.Exception e) {
                    //specific code for exceptions
                }
     
                return null;
            }
            
            protected void succeeded() {
            }
        }
    Theorically the TaskMonitor should react when a new Task occurs :confused:
    I must be missing something :rolleyes:

    Any help will be more than welcome! ;)

    -Sebastien

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Question how to determine task length?

    Okay, so how do we determine how long RSA will take on this:
    Java Code:
        final java.lang.String[][] RevisedProgram=
        {
            {"class HellWorldApp extends HellWorld"},
            {"{"},
            {"    public HelloWorldApp()"},
            {"    {"},
            {"         super();//"},
            {"    }"},
            {"    // main method, standard entry point for system to lauch application."},
            {"    public static void main(String[] args)"},
            {"    {"},
            {"        System.out.println(\"With blinding applied, the decryption time is no longer correlated to the value of the input ciphertext and so the timing attack fails.\"); // Display string."},
            {"    }"},
            {"}"},
        };
    Not being difficult, it is just that I do not see how we can set some upper bound for task completion ...
    Last edited by Nicholas Jordan; 11-23-2008 at 08:03 PM.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  3. #3
    SebScoFr is offline Member
    Join Date
    Nov 2008
    Posts
    3
    Rep Power
    0

    Default

    Well I'm not sure what you're talking about but I though that this code generated by netbeans for a Desktop Application should follow the task progress and update the progress bar:

    Java Code:
    TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
            taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
                @Override
                public void propertyChange(java.beans.PropertyChangeEvent evt) {
                    String propertyName = evt.getPropertyName();
                    System.out.println(propertyName);
                    if ("started".equals(propertyName)) {
                        if (!busyIconTimer.isRunning()) {
                            statusAnimationLabel.setIcon(busyIcons[0]);
                            busyIconIndex = 0;
                            busyIconTimer.start();
                        }
                        progressBar.setIndeterminate(true);
                    } else if ("done".equals(propertyName)) {
                        busyIconTimer.stop();
                        statusAnimationLabel.setIcon(idleIcon);
                        progressBar.setValue(0);
                    } else if ("message".equals(propertyName)) {
                        String text = (String)(evt.getNewValue());
                        statusMessageLabel.setText((text == null) ? "" : text);
                        messageTimer.restart();
                    } else if ("progress".equals(propertyName)) {
                        int value = (Integer)(evt.getNewValue());
                        progressBar.setIndeterminate(false);
                        progressBar.setValue(value);
                    }
                }
            });
    I might be wrong, and if it's the case, any idea how to do it?

    Thanks

  4. #4
    SebScoFr is offline Member
    Join Date
    Nov 2008
    Posts
    3
    Rep Power
    0

    Default

    The task wasn't actually recognized by the TaskMonitor, here is what I've done

    The button which start the Task
    Java Code:
    private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {
        this.startEncrypt();
    }
    And the Task
    Java Code:
        @Action
        public Task startEncrypt() {
            StartEncryptTask task = new StartEncryptTask(org.jdesktop.application.Application.getInstance());
    
            ApplicationContext C = getApplication().getContext();
            TaskMonitor M = C.getTaskMonitor();
            TaskService S = C.getTaskService();
            S.execute(task);
            M.setForegroundTask(task);
    
            return task;
        }
     
        private class StartEncryptTask extends Task<Void, Void> {
            StartEncryptTask(org.jdesktop.application.Application app) {
                super(app);
            }
            
            @Override
            protected Void doInBackground() {
                try {
                    //specific code for encryption
                }
                catch(java.lang.Exception e) {
                    //specific code for exceptions
                }
     
                return null;
            }
            
            protected void succeeded() {
            }
        }
    Hope that can help :cool:

Similar Threads

  1. Deployment of JRE 6 u7 to desktop pc / Configuration
    By rrathbun in forum New To Java
    Replies: 0
    Last Post: 09-12-2008, 09:37 PM
  2. three tier Desktop Application
    By newmember in forum AWT / Swing
    Replies: 0
    Last Post: 07-27-2008, 04:10 PM
  3. Desktop search in java
    By hellosubs in forum New To Java
    Replies: 0
    Last Post: 06-15-2008, 04:33 PM
  4. Spliting desktop
    By nagarte in forum AWT / Swing
    Replies: 5
    Last Post: 05-05-2008, 01:56 PM
  5. k5n Desktop Calendar 0.9.0
    By levent in forum Java Software
    Replies: 0
    Last Post: 06-02-2007, 08:13 AM

Posting Permissions

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